From: drh Date: Sat, 1 Oct 2016 00:37:50 +0000 (+0000) Subject: Avoid unnecessary zeroing of fields in the Vdbe object when it is allocated. X-Git-Tag: version-3.15.0~35 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ab3182f7c4ed7b6f8f7cc7394db24d73293ebab5;p=thirdparty%2Fsqlite.git Avoid unnecessary zeroing of fields in the Vdbe object when it is allocated. FossilOrigin-Name: 1e21bbe836539e64d24857f4faa3d12cd607dc7e --- diff --git a/manifest b/manifest index 4d02da0553..7526f661e6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sinitializing\sthe\scolumn-cache\ssection\sof\sthe\sParse\sobject,\ssince\sentries\nin\sthe\scache\swill\sbe\sinitialized\sas\sthey\sare\sused,\sand\savoiding\sthe\sinitial\nmemset()\ssaves\smany\sCPU\scycles. -D 2016-09-30T22:24:29.959 +C Avoid\sunnecessary\szeroing\sof\sfields\sin\sthe\sVdbe\sobject\swhen\sit\sis\sallocated. +D 2016-10-01T00:37:50.922 F Makefile.in 6fd48ffcf7c2deea7499062d1f3747f986c19678 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 5151cc64c4c05f3455f4f692ad11410a810d937f @@ -455,9 +455,9 @@ F src/util.c 3e2da6101888d073e79ecc6af5e0a2f70fa1e498 F src/vacuum.c 913970b9d86dd6c2b8063ef1af421880f1464ec3 F src/vdbe.c 51e754eec26d892abc6279f5e949545af68ec1b3 F src/vdbe.h c044be7050ac6bf596eecc6ab159f5dbc020a3b7 -F src/vdbeInt.h 581b737c2f6e413c555469480efe31796a71bcad +F src/vdbeInt.h 0a18713d0a2fec6807d076bd333d9bf3e57530cd F src/vdbeapi.c 794f80669e9e3b9b3edc78d80c15968985c7bf21 -F src/vdbeaux.c 5f97a1aed18b5b064407652654f73f3cd4836a87 +F src/vdbeaux.c 4c0678a2a2c315534a2609de515d04cccf3990fb F src/vdbeblob.c 3e82a797b60c3b9fed7b8de8c539ca7607874937 F src/vdbemem.c 1c330522e6b6e4ddd2ff63c4c0dfafa20c3965a7 F src/vdbesort.c 91fda3909326860382b0ca8aa251e609c6a9d62c @@ -1525,7 +1525,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ab12fce3318db447995e1465f34a1e43cd623d6a -R 0a3a2f22297400a0c501bf7a0c2b0caa +P 63cf7eafae5c3c1379edf416c5157010c7c120b5 +R 85f9a9479e2ad57a2952b90cd8e20395 U drh -Z fb861c120dabfe63359c1b99efc6b84b +Z e3416eaec67cf3f8ba5f96a2088d495d diff --git a/manifest.uuid b/manifest.uuid index e3eee84b50..2c3cf85d9a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -63cf7eafae5c3c1379edf416c5157010c7c120b5 \ No newline at end of file +1e21bbe836539e64d24857f4faa3d12cd607dc7e \ No newline at end of file diff --git a/src/vdbeInt.h b/src/vdbeInt.h index 353abc6877..1c6ee3f63b 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -340,34 +340,47 @@ struct ScanStatus { */ struct Vdbe { sqlite3 *db; /* The database connection that owns this statement */ + Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */ + Parse *pParse; /* Parsing context used to create this Vdbe */ + ynVar nVar; /* Number of entries in aVar[] */ + ynVar nzVar; /* Number of entries in azVar[] */ + u32 magic; /* Magic number for sanity checking */ + int nMem; /* Number of memory locations currently allocated */ + int nCursor; /* Number of slots in apCsr[] */ + u32 cacheCtr; /* VdbeCursor row cache generation counter */ + int pc; /* The program counter */ + int rc; /* Value to return */ + int nChange; /* Number of db changes made since last reset */ + int iStatement; /* Statement number (or 0 if has not opened stmt) */ + i64 iCurrentTime; /* Value of julianday('now') for this statement */ + i64 nFkConstraint; /* Number of imm. FK constraints this VM */ + i64 nStmtDefCons; /* Number of def. constraints when stmt started */ + i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */ + + /* When allocating a new Vdbe object, all of the fields below should be + ** initialized to zero or NULL */ + Op *aOp; /* Space to hold the virtual machine's program */ Mem *aMem; /* The memory locations */ Mem **apArg; /* Arguments to currently executing user function */ Mem *aColName; /* Column names to return */ Mem *pResultSet; /* Pointer to an array of results */ - Parse *pParse; /* Parsing context used to create this Vdbe */ - int nMem; /* Number of memory locations currently allocated */ - int nOp; /* Number of instructions in the program */ - int nCursor; /* Number of slots in apCsr[] */ - u32 magic; /* Magic number for sanity checking */ char *zErrMsg; /* Error message written here */ - Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */ VdbeCursor **apCsr; /* One element of this array for each open cursor */ Mem *aVar; /* Values for the OP_Variable opcode. */ char **azVar; /* Name of variables */ - ynVar nVar; /* Number of entries in aVar[] */ - ynVar nzVar; /* Number of entries in azVar[] */ - u32 cacheCtr; /* VdbeCursor row cache generation counter */ - int pc; /* The program counter */ - int rc; /* Value to return */ +#ifndef SQLITE_OMIT_TRACE + i64 startTime; /* Time when query started - used for profiling */ +#endif + int nOp; /* Number of instructions in the program */ #ifdef SQLITE_DEBUG int rcApp; /* errcode set by sqlite3_result_error_code() */ #endif u16 nResColumn; /* Number of columns in one row of the result set */ u8 errorAction; /* Recovery action to do in case of an error */ + u8 minWriteFileFormat; /* Minimum file format for writable database files */ bft expired:1; /* True if the VM needs to be recompiled */ bft doingRerun:1; /* True if rerunning after an auto-reprepare */ - u8 minWriteFileFormat; /* Minimum file format for writable database files */ bft explain:2; /* True if EXPLAIN present on SQL command */ bft changeCntOn:1; /* True to update the change-counter */ bft runOnlyOnce:1; /* Automatically expire on reset */ @@ -375,18 +388,9 @@ struct Vdbe { bft readOnly:1; /* True for statements that do not write */ bft bIsReader:1; /* True for statements that read */ bft isPrepareV2:1; /* True if prepared with prepare_v2() */ - int nChange; /* Number of db changes made since last reset */ yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */ yDbMask lockMask; /* Subset of btreeMask that requires a lock */ - int iStatement; /* Statement number (or 0 if has not opened stmt) */ u32 aCounter[5]; /* Counters used by sqlite3_stmt_status() */ -#ifndef SQLITE_OMIT_TRACE - i64 startTime; /* Time when query started - used for profiling */ -#endif - i64 iCurrentTime; /* Value of julianday('now') for this statement */ - i64 nFkConstraint; /* Number of imm. FK constraints this VM */ - i64 nStmtDefCons; /* Number of def. constraints when stmt started */ - i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */ char *zSql; /* Text of the SQL statement that generated this */ void *pFree; /* Free this when deleting the vdbe */ VdbeFrame *pFrame; /* Parent frame */ @@ -405,10 +409,11 @@ struct Vdbe { /* ** The following are allowed values for Vdbe.magic */ -#define VDBE_MAGIC_INIT 0x26bceaa5 /* Building a VDBE program */ -#define VDBE_MAGIC_RUN 0xbdf20da3 /* VDBE is ready to execute */ -#define VDBE_MAGIC_HALT 0x519c2973 /* VDBE has completed execution */ -#define VDBE_MAGIC_DEAD 0xb606c3c8 /* The VDBE has been deallocated */ +#define VDBE_MAGIC_INIT 0x16bceaa5 /* Building a VDBE program */ +#define VDBE_MAGIC_RUN 0x2df20da3 /* VDBE is ready to execute */ +#define VDBE_MAGIC_HALT 0x319c2973 /* VDBE has completed execution */ +#define VDBE_MAGIC_RESET 0x48fa9f76 /* Reset and ready to run again */ +#define VDBE_MAGIC_DEAD 0x5606c3c8 /* The VDBE has been deallocated */ /* ** Structure used to store the context required by the diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 86f5096a8b..26fee27657 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -21,8 +21,9 @@ Vdbe *sqlite3VdbeCreate(Parse *pParse){ sqlite3 *db = pParse->db; Vdbe *p; - p = sqlite3DbMallocZero(db, sizeof(Vdbe) ); + p = sqlite3DbMallocRaw(db, sizeof(Vdbe) ); if( p==0 ) return 0; + memset(&p->aOp, 0, sizeof(Vdbe)-offsetof(Vdbe,aOp)); p->db = db; if( db->pVdbe ){ db->pVdbe->pPrev = p; @@ -1826,7 +1827,7 @@ void sqlite3VdbeRewind(Vdbe *p){ int i; #endif assert( p!=0 ); - assert( p->magic==VDBE_MAGIC_INIT ); + assert( p->magic==VDBE_MAGIC_INIT || p->magic==VDBE_MAGIC_RESET ); /* There should be at least one opcode. */ @@ -1953,7 +1954,11 @@ void sqlite3VdbeMakeReady( pParse->nzVar = 0; pParse->azVar = 0; p->explain = pParse->explain; - if( db->mallocFailed==0 ){ + if( db->mallocFailed ){ + p->nVar = 0; + p->nCursor = 0; + p->nMem = 0; + }else{ p->nCursor = nCursor; p->nVar = (ynVar)nVar; initMemArray(p->aVar, nVar, db, MEM_Null); @@ -2880,7 +2885,7 @@ int sqlite3VdbeReset(Vdbe *p){ } #endif p->iCurrentTime = 0; - p->magic = VDBE_MAGIC_INIT; + p->magic = VDBE_MAGIC_RESET; return p->rc & db->errMask; } @@ -2951,7 +2956,9 @@ void sqlite3VdbeClearObject(sqlite3 *db, Vdbe *p){ vdbeFreeOpArray(db, pSub->aOp, pSub->nOp); sqlite3DbFree(db, pSub); } - for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]); + if( p->magic!=VDBE_MAGIC_INIT ){ + for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]); + } sqlite3DbFree(db, p->azVar); vdbeFreeOpArray(db, p->aOp, p->nOp); sqlite3DbFree(db, p->aColName);