From: drh Date: Thu, 24 Jul 2008 23:34:07 +0000 (+0000) Subject: Reduce the size of the parser allocation. Add additional instrumentation X-Git-Tag: version-3.6.10~705 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2abcd58f09da0d98118c4a2d2cb78f40dbc6a2ca;p=thirdparty%2Fsqlite.git Reduce the size of the parser allocation. Add additional instrumentation to mem2. speed1*.test uses scratch malloc. (CVS 5472) FossilOrigin-Name: 599a9dea8fc97d0e7f09e67c9954de8cc1b8748e --- diff --git a/manifest b/manifest index 555dbdaf41..38d50b766f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Use\sa\snew\salgorithm\sfor\ssqlite3Strlen\sthat\sis\sslightly\sslower\sbut\sis\smore\nlike\sto\swork\son\sa\smixture\sof\s32-\sand\s64-bit\ssystems.\s\sTicket\s#3237,\s#3248.\s(CVS\s5471) -D 2008-07-24T17:06:48 +C Reduce\sthe\ssize\sof\sthe\sparser\sallocation.\s\sAdd\sadditional\sinstrumentation\nto\smem2.\s\sspeed1*.test\suses\sscratch\smalloc.\s(CVS\s5472) +D 2008-07-24T23:34:07 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 77ff156061bb870aa0a8b3d545c670d08070f7e6 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -119,7 +119,7 @@ F src/main.c 6aeae6ec84ad3e023eaa619651079d45900959bc F src/malloc.c c4b525896b8c188dab98609180d13dbeeeb33a84 F src/md5.c 008216bbb5d34c6fbab5357aa68575ad8a31516a F src/mem1.c 08f95af5095ba5d1fae17deb0ea186e8cdefd8fa -F src/mem2.c 1e14a86d12dff279427cc52bb41ce5d80f138137 +F src/mem2.c 01726714af78c144b5f1f76338bd094deaab1789 F src/mem3.c c73e935d0b900abc51d5fa45f880937b062f4a9f F src/mem4.c 6703adb1717b26d9d70a1c2586b4b7b7ffee7909 F src/mem5.c 0b0ba1c2a02d86eb812dea6debacee841e3856f7 @@ -474,9 +474,9 @@ F test/sidedelete.test 736ac1da08b3b1aa62df97fef2fcdb1b660111b9 F test/soak.test 3c317b3e55e1160731030c8e865d1858fab66fea F test/softheap1.test 73ebd6e020d2954d965da2072baba5922fc8fb6a F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5 -F test/speed1.test 22e1b27af0683ed44dcd2f93ed817a9c3e65084a +F test/speed1.test cd5d9302f18946c18570e9ce6c736a5e283c8fcf F test/speed1p.explain d841e650a04728b39e6740296b852dccdca9b2cb -F test/speed1p.test 5f79987671f930a8aa651091c2952c1782b0df83 +F test/speed1p.test 1c932ff428cd7c26f0324a6ac59b16dfb2fd8efa F test/speed2.test 53177056baf6556dcbdcf032bbdfc41c1aa74ded F test/speed3.test e312d7e442a5047d730569fdae2ba99bc94e1a13 F test/speed4.test abc0ad3399dcf9703abed2fff8705e4f8e416715 @@ -591,7 +591,7 @@ F test/zeroblob.test 792124852ec61458a2eb527b5091791215e0be95 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b F tool/fragck.tcl 5265a95126abcf6ab357f7efa544787e5963f439 F tool/lemon.c 13e9c37ab9e0cc182cc10b93ac0e5270bbf472c8 -F tool/lempar.c 1a2caec816704bce9ebefeb4b46f54d6b2f8970e +F tool/lempar.c 82ad5e30f2da013a13dc934e582b85916d456b50 F tool/memleak.awk 4e7690a51bf3ed757e611273d43fe3f65b510133 F tool/memleak2.awk 9cc20c8e8f3c675efac71ea0721ee6874a1566e8 F tool/memleak3.tcl 7707006ee908cffff210c98158788d85bb3fcdbf @@ -612,7 +612,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P 7455310931787ddc72d677ba6c471b67af9418a8 -R 2dc3c49d1cf459d9463d2096757fe3cd +P cb1876d8dc102be74be98dd57ac14ee67be8e8e2 +R 71cb87040ca7c102d12bf7d55288c874 U drh -Z 6ffb5de8a8a5e4cc894ca126c9cfb890 +Z 3828cdd4b6a6e072ef07f4672692577c diff --git a/manifest.uuid b/manifest.uuid index dcc9c53d1e..a0a0250e88 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cb1876d8dc102be74be98dd57ac14ee67be8e8e2 \ No newline at end of file +599a9dea8fc97d0e7f09e67c9954de8cc1b8748e \ No newline at end of file diff --git a/src/mem2.c b/src/mem2.c index 46ae707e6b..33c8cfeffc 100644 --- a/src/mem2.c +++ b/src/mem2.c @@ -19,7 +19,7 @@ ** This file contains implementations of the low-level memory allocation ** routines specified in the sqlite3_mem_methods object. ** -** $Id: mem2.c,v 1.35 2008/07/24 08:20:40 danielk1977 Exp $ +** $Id: mem2.c,v 1.36 2008/07/24 23:34:07 drh Exp $ */ #include "sqliteInt.h" @@ -113,14 +113,37 @@ static struct { /* ** Gather statistics on the sizes of memory allocations. - ** sizeCnt[i] is the number of allocation attempts of i*8 + ** nAlloc[i] is the number of allocation attempts of i*8 ** bytes. i==NCSIZE is the number of allocation attempts for ** sizes more than NCSIZE*8 bytes. */ - int sizeCnt[NCSIZE]; + int nAlloc[NCSIZE]; /* Total number of allocations */ + int nCurrent[NCSIZE]; /* Current number of allocations */ + int mxCurrent[NCSIZE]; /* Highwater mark for nCurrent */ } mem; + +/* +** Adjust memory usage statistics +*/ +static void adjustStats(int iSize, int increment){ + int i = ((iSize+7)&~7)/8; + if( i>NCSIZE-1 ){ + i = NCSIZE - 1; + } + if( increment>0 ){ + mem.nAlloc[i]++; + mem.nCurrent[i]++; + if( mem.nCurrent[i]>mem.mxCurrent[i] ){ + mem.mxCurrent[i] = mem.nCurrent[i]; + } + }else{ + mem.nCurrent[i]--; + assert( mem.nCurrent[i]>=0 ); + } +} + /* ** Given an allocation, find the MemBlockHdr for that allocation. ** @@ -198,11 +221,6 @@ static void *sqlite3MemMalloc(int nByte){ sqlite3_mutex_enter(mem.mutex); assert( mem.disallow==0 ); nReserve = (nByte+7)&~7; - if( nReserve/8>NCSIZE-1 ){ - mem.sizeCnt[NCSIZE-1]++; - }else{ - mem.sizeCnt[nReserve/8]++; - } totalSize = nReserve + sizeof(*pHdr) + sizeof(int) + mem.nBacktrace*sizeof(void*) + mem.nTitle; p = malloc(totalSize); @@ -235,6 +253,7 @@ static void *sqlite3MemMalloc(int nByte){ memcpy(z, mem.zTitle, mem.nTitle); } pHdr->iSize = nByte; + adjustStats(nByte, +1); pInt = (int*)&pHdr[1]; pInt[nReserve/sizeof(int)] = REARGUARD; memset(pInt, 0x65, nReserve); @@ -272,6 +291,7 @@ static void sqlite3MemFree(void *pPrior){ } z = (char*)pBt; z -= pHdr->nTitle; + adjustStats(pHdr->iSize, -1); memset(z, 0x2b, sizeof(void*)*pHdr->nBacktraceSlots + sizeof(*pHdr) + pHdr->iSize + sizeof(int) + pHdr->nTitle); free(z); @@ -394,12 +414,15 @@ void sqlite3MemdebugDump(const char *zFilename){ } fprintf(out, "COUNTS:\n"); for(i=0; i%3d: %d\n", NCSIZE*8, mem.sizeCnt[NCSIZE-1]); + if( mem.nAlloc[NCSIZE-1] ){ + fprintf(out, " %5d: %10d %10d %10d\n", + NCSIZE*8-8, mem.nAlloc[NCSIZE-1], + mem.nCurrent[NCSIZE-1], mem.mxCurrent[NCSIZE-1]); } fclose(out); } @@ -411,7 +434,7 @@ int sqlite3MemdebugMallocCount(){ int i; int nTotal = 0; for(i=0; i