From: drh Date: Sat, 10 Dec 2016 00:14:23 +0000 (+0000) Subject: In balance_nonroot, try to combine dropCell/insertCell combinations for the X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fheads%2Ffailed-dropCell-opt;p=thirdparty%2Fsqlite.git In balance_nonroot, try to combine dropCell/insertCell combinations for the dividers into a cell overwrites. This results in a very small (0.05%) performance gain which is probably not worth the added complexity. FossilOrigin-Name: 478627c9e949ffa97979cc91506b8c79a2aef484 --- diff --git a/manifest b/manifest index 45507e32cb..fdbb095577 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sdoing\sthe\ssqlite3BtreeInsert()\soverwrite\soptimization,\smake\ssure\sthe\nmemcpy()\sdoes\snot\sextend\soff\sthe\send\sof\sthe\spage. -D 2016-12-09T19:42:18.129 +C In\sbalance_nonroot,\stry\sto\scombine\sdropCell/insertCell\scombinations\sfor\sthe\ndividers\sinto\sa\scell\soverwrites.\s\sThis\sresults\sin\sa\svery\ssmall\s(0.05%)\nperformance\sgain\swhich\sis\sprobably\snot\sworth\sthe\sadded\scomplexity. +D 2016-12-10T00:14:23.419 F Makefile.in 7639c6a09da11a9c7c6f2630fc981ee588d1072d F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da @@ -331,7 +331,7 @@ F src/auth.c 930b376a9c56998557367e6f7f8aaeac82a2a792 F src/backup.c faf17e60b43233c214aae6a8179d24503a61e83b F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33 F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73 -F src/btree.c 217c9900de7cf04997aff25faabc366cfe84e8f1 +F src/btree.c 518b5a3692a3d2a4bee8628fa9a300d286377f7f F src/btree.h 2349a588abcd7e0c04f984e15c5c777b61637583 F src/btreeInt.h 10c4b77c2fb399580babbcc7cf652ac10dba796e F src/build.c 178f16698cbcb43402c343a9413fe22c99ffee21 @@ -1536,7 +1536,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c1f0ae9d2981a19875103750379ad26f2575f878 -R 956ba83a1c02ce8b54106bed68f282ac +P 684ef4582ed19b2af22dda6fc085c70464f92f1b +R d49f83677b094a47cc3a2fe599b3e886 +T *branch * failed-dropCell-opt +T *sym-failed-dropCell-opt * +T -sym-trunk * U drh -Z 1db7deef38744b5038e919d70ebcde44 +Z fdade63ef998e2e74e6a87d6f3697018 diff --git a/manifest.uuid b/manifest.uuid index ea8d54ff5b..22576fd555 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -684ef4582ed19b2af22dda6fc085c70464f92f1b \ No newline at end of file +478627c9e949ffa97979cc91506b8c79a2aef484 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index b7e16a85f2..f2665f8c3b 100644 --- a/src/btree.c +++ b/src/btree.c @@ -7017,12 +7017,18 @@ static int balance_nonroot( Pgno aPgno[NB+2]; /* Page numbers of new pages before shuffling */ Pgno aPgOrder[NB+2]; /* Copy of aPgno[] used for sorting pages */ u16 aPgFlags[NB+2]; /* flags field of new pages before shuffling */ - CellArray b; /* Parsed information on cells being balanced */ + CellArray b; /* Parsed information on cells being balanced */ + struct DeferredDropCell { /* Deferred calls to dropCell() for pParent */ + u16 idx; /* The index of the cell to drop */ + u16 sz; /* The size of the cell to drop */ + } sDDC0, sDDC1; /* Up to 2 deferred calls */ memset(abDone, 0, sizeof(abDone)); b.nCell = 0; b.apCell = 0; pBt = pParent->pBt; + sDDC0.sz = sDDC0.idx = 0; + sDDC1.sz = sDDC1.idx = 0; assert( sqlite3_mutex_held(pBt->mutex) ); assert( sqlite3PagerIswriteable(pParent->pDbPage) ); @@ -7118,7 +7124,12 @@ static int balance_nonroot( apDiv[i] = &aOvflSpace[apDiv[i]-pParent->aData]; } } - dropCell(pParent, i+nxDiv-pParent->nOverflow, szNew[i], &rc); + assert( sDDC1.sz==0 ); + sDDC1 = sDDC0; + sDDC0.idx = i+nxDiv-pParent->nOverflow; + sDDC0.sz = szNew[i]; +//printf("dropCell:\n"); +// dropCell(pParent, i+nxDiv-pParent->nOverflow, szNew[i], &rc); } } @@ -7586,10 +7597,34 @@ static int balance_nonroot( iOvflSpace += sz; assert( sz<=pBt->maxLocal+23 ); assert( iOvflSpace <= (int)pBt->pageSize ); - insertCell(pParent, nxDiv+i, pCell, sz, pTemp, pNew->pgno, &rc); + if( sDDC0.idx==nxDiv+i && sDDC0.sz==sz ){ + /* overwrite */ + unsigned char *oldCell = findCell(pParent, sDDC0.idx); +//printf("overwrite: pg=%d idx=%d sz=%d\n", pParent->pgno, sDDC0.idx, sDDC0.sz); + memcpy(oldCell+4, pCell+4, sz-4); + put4byte(oldCell, pNew->pgno); + sDDC0 = sDDC1; + sDDC1.sz = 0; + }else{ + if( sDDC0.sz>0 ){ + if( sDDC1.sz>0 ){ +//printf("dropCell: pg=%d idx=%d sz=%d\n", pParent->pgno, sDDC1.idx, sDDC1.sz); + dropCell(pParent, sDDC1.idx, sDDC1.sz, &rc); + sDDC1.sz = 0; + } +//printf("dropCell: pg=%d idx=%d sz=%d\n", pParent->pgno, sDDC0.idx, sDDC0.sz); + dropCell(pParent, sDDC0.idx, sDDC0.sz, &rc); + sDDC0.sz = 0; + if( rc ) goto balance_cleanup; + } +//printf("insertCell: pg=%d idx=%d sz=%d\n", pParent->pgno, nxDiv+i, sz); + insertCell(pParent, nxDiv+i, pCell, sz, pTemp, pNew->pgno, &rc); + } if( rc!=SQLITE_OK ) goto balance_cleanup; assert( sqlite3PagerIswriteable(pParent->pDbPage) ); } + if( sDDC1.sz ) dropCell(pParent, sDDC1.idx, sDDC1.sz, &rc); + if( sDDC0.sz ) dropCell(pParent, sDDC0.idx, sDDC0.sz, &rc); /* Now update the actual sibling pages. The order in which they are updated ** is important, as this code needs to avoid disrupting any page from which