From: drh Date: Fri, 22 Aug 2014 22:26:07 +0000 (+0000) Subject: Factor the saveAllCursors() routine of btree.c into two separate routines, X-Git-Tag: version-3.8.7~167 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=637f3d83b9455eeb87bce698877f9d8c03ec912b;p=thirdparty%2Fsqlite.git Factor the saveAllCursors() routine of btree.c into two separate routines, for a noticable performance improvement. FossilOrigin-Name: 3eb084390382c108e9b0ff0b29dede58ebb149bc --- diff --git a/manifest b/manifest index 812c653a73..a0fd1d8b2e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Performance\senhancements\sin\sthe\sb-tree\smutex\slogic. -D 2014-08-22T21:58:10.354 +C Factor\sthe\ssaveAllCursors()\sroutine\sof\sbtree.c\sinto\stwo\sseparate\sroutines,\nfor\sa\snoticable\sperformance\simprovement. +D 2014-08-22T22:26:07.834 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -168,7 +168,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c a31809c65623cc41849b94d368917f8bb66e6a7e F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c ec9d3f1295dafeb278c3830211cc5584132468f4 -F src/btree.c 4195fed5741b4dbcc9831b623aec487258f3e62d +F src/btree.c 776885dfef3033af7e8eabbf004481f219870a1d F src/btree.h 4245a349bfe09611d7ff887dbc3a80cee8b7955a F src/btreeInt.h cf180d86b2e9e418f638d65baa425c4c69c0e0e3 F src/build.c 058e3aadb1376521ff291735237edf4c10f438fb @@ -1188,7 +1188,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 6bcf1af6a48dbda5ac6f6b3b02810bdfc4730000 -R 24d5ffe2f1d9679a613707454c70f45a +P 8914530644f938a7a98e25ea1fb0bca1f9d79101 +R 036983fb95199f1ba06f1397f389a453 U drh -Z 6801ae93f83fb9ed7a247305de8bd03a +Z 9ea20fed62648c22294e9e322338cabb diff --git a/manifest.uuid b/manifest.uuid index 5367fb5584..334a3ae4c0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8914530644f938a7a98e25ea1fb0bca1f9d79101 \ No newline at end of file +3eb084390382c108e9b0ff0b29dede58ebb149bc \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 56718b69d6..6da3715e30 100644 --- a/src/btree.c +++ b/src/btree.c @@ -629,16 +629,42 @@ static int saveCursorPosition(BtCursor *pCur){ return rc; } +/* Forward reference */ +static int SQLITE_NOINLINE saveCursorsOnList(BtCursor*,Pgno,BtCursor*); + /* ** Save the positions of all cursors (except pExcept) that are open on -** the table with root-page iRoot. Usually, this is called just before cursor -** pExcept is used to modify the table (BtreeDelete() or BtreeInsert()). +** the table with root-page iRoot. "Saving the cursor position" means that +** the location in the btree is remembered in such a way that it can be +** moved back to the same spot after the btree has been modified. This +** routine is called just before cursor pExcept is used to modify the +** table, for example in BtreeDelete() or BtreeInsert(). +** +** Implementation note: This routine merely checks to see if any cursors +** need to be saved. It calls out to saveCursorsOnList() in the (unusual) +** event that cursors are in need to being saved. */ static int saveAllCursors(BtShared *pBt, Pgno iRoot, BtCursor *pExcept){ - BtCursor *p; assert( sqlite3_mutex_held(pBt->mutex) ); assert( pExcept==0 || pExcept->pBt==pBt ); + BtCursor *p; for(p=pBt->pCursor; p; p=p->pNext){ + if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ) break; + } + return p ? saveCursorsOnList(p, iRoot, pExcept) : SQLITE_OK; +} + +/* This helper routine to saveAllCursors does the actual work of saving +** the cursors if and when a cursor is found that actually requires saving. +** The common case is that no cursors need to be saved, so this routine is +** broken out from its caller to avoid unnecessary stack pointer movement. +*/ +static int SQLITE_NOINLINE saveCursorsOnList( + BtCursor *p, /* The first cursor that needs saving */ + Pgno iRoot, /* Only save cursor with this iRoot. Save all if zero */ + BtCursor *pExcept /* Do not save this cursor */ +){ + do{ if( p!=pExcept && (0==iRoot || p->pgnoRoot==iRoot) ){ if( p->eState==CURSOR_VALID ){ int rc = saveCursorPosition(p); @@ -650,7 +676,8 @@ static int saveAllCursors(BtShared *pBt, Pgno iRoot, BtCursor *pExcept){ btreeReleaseAllCursorPages(p); } } - } + p = p->pNext; + }while( p ); return SQLITE_OK; }