From: drh Date: Mon, 11 Apr 2016 18:15:37 +0000 (+0000) Subject: Performance optimizations in the column cache of the code generator, and X-Git-Tag: version-3.13.0~105 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bea119cdebd9fa581302c0e3f5d8c31ca0628965;p=thirdparty%2Fsqlite.git Performance optimizations in the column cache of the code generator, and especially the sqlite3ExprCacheRemove() routine. FossilOrigin-Name: e35b345cf858018ae0c07f79725f8d58062168db --- diff --git a/manifest b/manifest index c6cd43627e..278efe9dfc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplification\sand\sperformance\simprovements\sin\ssqlite3ExprDup()\sand\sits\nsubroutines.\s\sMore\swork\sis\spossible\sin\sthis\sarea. -D 2016-04-11T16:43:43.285 +C Performance\soptimizations\sin\sthe\scolumn\scache\sof\sthe\scode\sgenerator,\sand\nespecially\sthe\ssqlite3ExprCacheRemove()\sroutine. +D 2016-04-11T18:15:37.821 F Makefile.in eba680121821b8a60940a81454316f47a341487a F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 1f123a0757f6f04f0341accb46457e116817159a @@ -329,7 +329,7 @@ F src/ctime.c 60e135af364d777a9ab41c97e5e89cd224da6198 F src/date.c 0b73e681c11fca867fec554750c07fe0d4e417c1 F src/dbstat.c c845548d4346e606e2f2b7d2e714ace2b8a7dd1b F src/delete.c 78eb999114ec04fcf1b7d123ccedb4b5b734930e -F src/expr.c 16829fcf84b41d16b3d2e74e4e30ea8315cbba88 +F src/expr.c 22d553f3e6425586513219a9dfbbf6c57581c736 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 4c0bd09e602b8ae8d36d81e31e4872d0b53c87bb F src/func.c 552d300265aed09eea21f68ac742a440550c0062 @@ -380,7 +380,7 @@ F src/shell.c b7922fa264f8c8d72a5ec6dd0b091e15a93c4de5 F src/sqlite.h.in c8f41612dc1a9b5212a891e1b65a5f589b8b884a F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 98f72cbfe00169c39089115427d06ea05fe4b4a2 -F src/sqliteInt.h 8a3ca5847b3cbd0ee3333f5615e3db049f550727 +F src/sqliteInt.h e4a3229829dd20db9a0348d2119711272c33c757 F src/sqliteLimit.h c0373387c287c8d0932510b5547ecde31b5da247 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 5226df15ab9179b9ed558d89575ea0ce37b03fc9 @@ -1482,7 +1482,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 e554a4c38bda9c73bf129bb7c665c53ccc4d96a8 -R ddaad63736e0e0e6322e4bbbe74f8062 +P 476cc2838824e0667e80ce527b9caa551dee4a77 +R add6544c70f21201cd7c87d168cad7da U drh -Z db16ea712247dfbc518b4dea8f54265a +Z 1ce8fe8f94193e403ead86e0c919fda1 diff --git a/manifest.uuid b/manifest.uuid index c7adec1100..ce5bbdda1c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -476cc2838824e0667e80ce527b9caa551dee4a77 \ No newline at end of file +e35b345cf858018ae0c07f79725f8d58062168db \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 53ba58101c..37a7624db1 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2335,6 +2335,19 @@ static void codeInteger(Parse *pParse, Expr *pExpr, int negFlag, int iMem){ } } +#if defined(SQLITE_DEBUG) +/* +** Verify the consistency of the column cache +*/ +static int cacheIsValid(Parse *pParse){ + int i, n; + for(i=n=0; iaColCache[i].iReg>0 ) n++; + } + return n==pParse->nColCache; +} +#endif + /* ** Clear a cache entry. */ @@ -2345,6 +2358,9 @@ static void cacheEntryClear(Parse *pParse, struct yColCache *p){ } p->tempReg = 0; } + p->iReg = 0; + pParse->nColCache--; + assert( cacheIsValid(pParse) ); } @@ -2388,6 +2404,8 @@ void sqlite3ExprCacheStore(Parse *pParse, int iTab, int iCol, int iReg){ p->iReg = iReg; p->tempReg = 0; p->lru = pParse->iCacheCnt++; + pParse->nColCache++; + assert( cacheIsValid(pParse) ); return; } } @@ -2409,6 +2427,7 @@ void sqlite3ExprCacheStore(Parse *pParse, int iTab, int iCol, int iReg){ p->iReg = iReg; p->tempReg = 0; p->lru = pParse->iCacheCnt++; + assert( cacheIsValid(pParse) ); return; } } @@ -2418,15 +2437,13 @@ void sqlite3ExprCacheStore(Parse *pParse, int iTab, int iCol, int iReg){ ** Purge the range of registers from the column cache. */ void sqlite3ExprCacheRemove(Parse *pParse, int iReg, int nReg){ - int i; - int iLast = iReg + nReg - 1; struct yColCache *p; - for(i=0, p=pParse->aColCache; iiReg; - if( r>=iReg && r<=iLast ){ - cacheEntryClear(pParse, p); - p->iReg = 0; - } + if( iReg<=0 || pParse->nColCache==0 ) return; + p = &pParse->aColCache[SQLITE_N_COLCACHE-1]; + while(1){ + if( p->iReg >= iReg && p->iReg < iReg+nReg ) cacheEntryClear(pParse, p); + if( p==pParse->aColCache ) break; + p--; } } @@ -2462,7 +2479,6 @@ void sqlite3ExprCachePop(Parse *pParse){ for(i=0, p=pParse->aColCache; iiReg && p->iLevel>pParse->iCacheLevel ){ cacheEntryClear(pParse, p); - p->iReg = 0; } } } @@ -2597,7 +2613,6 @@ void sqlite3ExprCacheClear(Parse *pParse){ for(i=0, p=pParse->aColCache; iiReg ){ cacheEntryClear(pParse, p); - p->iReg = 0; } } } @@ -2639,6 +2654,7 @@ static int usedAsColumnCache(Parse *pParse, int iFrom, int iTo){ } #endif /* SQLITE_DEBUG || SQLITE_COVERAGE_TEST */ + /* ** Convert an expression node to a TK_REGISTER */ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index f9f449d967..1b0325254f 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2814,6 +2814,7 @@ struct Parse { u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */ u8 okConstFactor; /* OK to factor out constants */ u8 disableLookaside; /* Number of times lookaside has been disabled */ + u8 nColCache; /* Number of entries in aColCache[] */ int aTempReg[8]; /* Holding area for temporary registers */ int nRangeReg; /* Size of the temporary register block */ int iRangeReg; /* First register in temporary register block */