Minor performance improvement and size reduction for the btree-page space

allocator.

FossilOrigin-Name: 73637d12e31f5489efe37d8cf4ab50a1911d4c75
This commit is contained in:
drh 2014-08-20 00:54:46 +00:00
parent dfd1547b48
commit 75b31dc9ad
3 changed files with 18 additions and 13 deletions

View File

@ -1,5 +1,5 @@
C Modify\sthe\smemsubsys1-3.1.4\stest\sso\sthat\sit\sdoes\snot\sfail\sarbitrarily\sdue\nto\svariations\sin\sthe\sbehavior\sof\ssystem\smalloc(). C Minor\sperformance\simprovement\sand\ssize\sreduction\sfor\sthe\sbtree-page\sspace\nallocator.
D 2014-08-19T23:04:49.204 D 2014-08-20T00:54:46.809
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308 F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -167,7 +167,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
F src/backup.c a729e63cf5cd1829507cb7b8e89f99b95141bb53 F src/backup.c a729e63cf5cd1829507cb7b8e89f99b95141bb53
F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb
F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7
F src/btree.c fa057e30794bfd867963b44a3a42710a45c335a1 F src/btree.c c580f3fb3b3d1bf968e5c7e6a0ad48b7b0bd4366
F src/btree.h 4245a349bfe09611d7ff887dbc3a80cee8b7955a F src/btree.h 4245a349bfe09611d7ff887dbc3a80cee8b7955a
F src/btreeInt.h cf180d86b2e9e418f638d65baa425c4c69c0e0e3 F src/btreeInt.h cf180d86b2e9e418f638d65baa425c4c69c0e0e3
F src/build.c 5abf794fe8a605f2005b422e98a3cedad9b9ef5b F src/build.c 5abf794fe8a605f2005b422e98a3cedad9b9ef5b
@ -1186,7 +1186,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 44d5bd4cc3f76e9a151ba0abae1092bd184af264 P d280157da0b5275f3e3c875d2dcfb9998d374ac0
R da9b4e10fd35ea0494fda63ca4df66ec R 020501de111b3b2380806f2152969bc3
U drh U drh
Z 375791abd440beaccbf3e162957d1a64 Z 17df18c00e8e514c309dda1b0357fb11

View File

@ -1 +1 @@
d280157da0b5275f3e3c875d2dcfb9998d374ac0 73637d12e31f5489efe37d8cf4ab50a1911d4c75

View File

@ -1197,7 +1197,6 @@ static int defragmentPage(MemPage *pPage){
static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){
const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */ const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */
u8 * const data = pPage->aData; /* Local cache of pPage->aData */ u8 * const data = pPage->aData; /* Local cache of pPage->aData */
int nFrag; /* Number of fragmented bytes on pPage */
int top; /* First byte of cell content area */ int top; /* First byte of cell content area */
int gap; /* First byte of gap between cell pointers and cell content */ int gap; /* First byte of gap between cell pointers and cell content */
int rc; /* Integer return code */ int rc; /* Integer return code */
@ -1212,16 +1211,22 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){
usableSize = pPage->pBt->usableSize; usableSize = pPage->pBt->usableSize;
assert( nByte < usableSize-8 ); assert( nByte < usableSize-8 );
nFrag = data[hdr+7];
assert( pPage->cellOffset == hdr + 12 - 4*pPage->leaf ); assert( pPage->cellOffset == hdr + 12 - 4*pPage->leaf );
gap = pPage->cellOffset + 2*pPage->nCell; gap = pPage->cellOffset + 2*pPage->nCell;
top = get2byteNotZero(&data[hdr+5]); assert( gap<=65536 );
if( gap>top ) return SQLITE_CORRUPT_BKPT; top = get2byte(&data[hdr+5]);
if( gap>top ){
if( top==0 ){
top = 65536;
}else{
return SQLITE_CORRUPT_BKPT;
}
}
testcase( gap+2==top ); testcase( gap+2==top );
testcase( gap+1==top ); testcase( gap+1==top );
testcase( gap==top ); testcase( gap==top );
if( nFrag>=60 ){ if( data[hdr+7]>=60 ){
/* Always defragment highly fragmented pages */ /* Always defragment highly fragmented pages */
rc = defragmentPage(pPage); rc = defragmentPage(pPage);
if( rc ) return rc; if( rc ) return rc;
@ -1246,7 +1251,7 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){
/* Remove the slot from the free-list. Update the number of /* Remove the slot from the free-list. Update the number of
** fragmented bytes within the page. */ ** fragmented bytes within the page. */
memcpy(&data[addr], &data[pc], 2); memcpy(&data[addr], &data[pc], 2);
data[hdr+7] = (u8)(nFrag + x); data[hdr+7] += (u8)x;
}else if( size+pc > usableSize ){ }else if( size+pc > usableSize ){
return SQLITE_CORRUPT_BKPT; return SQLITE_CORRUPT_BKPT;
}else{ }else{