From: drh Date: Fri, 12 Jun 2015 13:49:26 +0000 (+0000) Subject: Add a fast-path implementation of pcache1Fetch() for the common case of X-Git-Tag: version-3.8.11~167^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=55a46c9b0e067f0776fe44f552479779249c4c55;p=thirdparty%2Fsqlite.git Add a fast-path implementation of pcache1Fetch() for the common case of separate caches that do not use a mutex. FossilOrigin-Name: 760700edb3ff1f5d6bf3058f874cc8e2808905c7 --- diff --git a/manifest b/manifest index f5a2a077ef..df814d0093 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\sperformance\soptimization\sin\spcache1.c. -D 2015-06-12T13:04:51.385 +C Add\sa\sfast-path\simplementation\sof\spcache1Fetch()\sfor\sthe\scommon\scase\sof\nseparate\scaches\sthat\sdo\snot\suse\sa\smutex. +D 2015-06-12T13:49:26.780 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 1063c58075b7400d93326b0eb332b48a54f53025 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -242,7 +242,7 @@ F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 F src/parse.y 6d60dda8f8d418b6dc034f1fbccd816c459983a8 F src/pcache.c 10539fb959849ad6efff80050541cab3d25089d4 F src/pcache.h b44658c9c932d203510279439d891a2a83e12ba8 -F src/pcache1.c 0f2c218d9fa84814403033319036d8e9ecb06dfd +F src/pcache1.c 0324126d981c6db4ba39e0a6b2bf79b690d3107f F src/pragma.c c1f4d012ea9f6b1ce52d341b2cd0ad72d560afd7 F src/pragma.h b8632d7cdda7b25323fa580e3e558a4f0d4502cc F src/prepare.c 82e5db1013846a819f198336fed72c44c974e7b1 @@ -1286,7 +1286,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 711a176cbfad5dde6defa9648fba6d0d663af134 -R 9bc91229df1369aa902663b713f0e063 +P 2e8ad2ead9d146e312c693d9b967bbd5b92429d9 +R 911300e4b1697824e69cfe439e19a5f8 +T *branch * faster-pcache1-fetch +T *sym-faster-pcache1-fetch * +T -sym-trunk * U drh -Z c8fd78f00b5d9acfb5119a0b1df9ec4a +Z e8ae5ddb4580a5169c907c35e69dd177 diff --git a/manifest.uuid b/manifest.uuid index 6055917edd..859267d458 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2e8ad2ead9d146e312c693d9b967bbd5b92429d9 \ No newline at end of file +760700edb3ff1f5d6bf3058f874cc8e2808905c7 \ No newline at end of file diff --git a/src/pcache1.c b/src/pcache1.c index 5b1f3ba0df..0a6d6d01d3 100644 --- a/src/pcache1.c +++ b/src/pcache1.c @@ -425,7 +425,7 @@ static void pcache1ResizeHash(PCache1 *p){ ** ** The PGroup mutex must be held when this function is called. */ -static void pcache1PinPage(PgHdr1 *pPage){ +static PgHdr1 *pcache1PinPage(PgHdr1 *pPage){ PCache1 *pCache; assert( pPage!=0 ); @@ -448,6 +448,7 @@ static void pcache1PinPage(PgHdr1 *pPage){ pPage->pLruPrev = 0; pPage->isPinned = 1; pCache->nRecyclable--; + return pPage; } @@ -803,8 +804,13 @@ static SQLITE_NOINLINE PgHdr1 *pcache1FetchStage2( ** proceed to step 5. ** ** 5. Otherwise, allocate and return a new page buffer. +** +** There are two versions of this routine. pcache1FetchWithMutex() is +** the general case. pcache1FetchNoMutex() is a faster implementation for +** the common case where pGroup->mutex is NULL. The pcache1Fetch() wrapper +** invokes the appropriate routine. */ -static sqlite3_pcache_page *pcache1Fetch( +static PgHdr1 *pcache1FetchNoMutex( sqlite3_pcache *p, unsigned int iKey, int createFlag @@ -812,28 +818,56 @@ static sqlite3_pcache_page *pcache1Fetch( PCache1 *pCache = (PCache1 *)p; PgHdr1 *pPage = 0; - assert( offsetof(PgHdr1,page)==0 ); - assert( pCache->bPurgeable || createFlag!=1 ); - assert( pCache->bPurgeable || pCache->nMin==0 ); - assert( pCache->bPurgeable==0 || pCache->nMin==10 ); - assert( pCache->nMin==0 || pCache->bPurgeable ); - assert( pCache->nHash>0 ); - pcache1EnterMutex(pCache->pGroup); - /* Step 1: Search the hash table for an existing entry. */ pPage = pCache->apHash[iKey % pCache->nHash]; while( pPage && pPage->iKey!=iKey ){ pPage = pPage->pNext; } /* Step 2: Abort if no existing page is found and createFlag is 0 */ if( pPage ){ - if( !pPage->isPinned ) pcache1PinPage(pPage); + if( !pPage->isPinned ){ + return pcache1PinPage(pPage); + }else{ + return pPage; + } }else if( createFlag ){ /* Steps 3, 4, and 5 implemented by this subroutine */ - pPage = pcache1FetchStage2(pCache, iKey, createFlag); + return pcache1FetchStage2(pCache, iKey, createFlag); + }else{ + return 0; } +} +static PgHdr1 *pcache1FetchWithMutex( + sqlite3_pcache *p, + unsigned int iKey, + int createFlag +){ + PCache1 *pCache = (PCache1 *)p; + PgHdr1 *pPage; + + pcache1EnterMutex(pCache->pGroup); + pPage = pcache1FetchNoMutex(p, iKey, createFlag); assert( pPage==0 || pCache->iMaxKey>=iKey ); pcache1LeaveMutex(pCache->pGroup); - return (sqlite3_pcache_page*)pPage; + return pPage; +} +static sqlite3_pcache_page *pcache1Fetch( + sqlite3_pcache *p, + unsigned int iKey, + int createFlag +){ + PCache1 *pCache = (PCache1 *)p; + + assert( offsetof(PgHdr1,page)==0 ); + assert( pCache->bPurgeable || createFlag!=1 ); + assert( pCache->bPurgeable || pCache->nMin==0 ); + assert( pCache->bPurgeable==0 || pCache->nMin==10 ); + assert( pCache->nMin==0 || pCache->bPurgeable ); + assert( pCache->nHash>0 ); + if( pCache->pGroup->mutex ){ + return (sqlite3_pcache_page*)pcache1FetchWithMutex(p, iKey, createFlag); + }else{ + return (sqlite3_pcache_page*)pcache1FetchNoMutex(p, iKey, createFlag); + } }