]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Reduce the size of the parser allocation. Add additional instrumentation
authordrh <drh@noemail.net>
Thu, 24 Jul 2008 23:34:07 +0000 (23:34 +0000)
committerdrh <drh@noemail.net>
Thu, 24 Jul 2008 23:34:07 +0000 (23:34 +0000)
to mem2.  speed1*.test uses scratch malloc. (CVS 5472)

FossilOrigin-Name: 599a9dea8fc97d0e7f09e67c9954de8cc1b8748e

manifest
manifest.uuid
src/mem2.c
test/speed1.test
test/speed1p.test
tool/lempar.c

index 555dbdaf41c450bc3347d771ee955532f9dc457e..38d50b766f7b247cd41951ef52181e2d0726991e 100644 (file)
--- 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
index dcc9c53d1ecde7c3931693e3ad59199730593925..a0a0250e882a76304b1c1d888a1cd4987381c55a 100644 (file)
@@ -1 +1 @@
-cb1876d8dc102be74be98dd57ac14ee67be8e8e2
\ No newline at end of file
+599a9dea8fc97d0e7f09e67c9954de8cc1b8748e
\ No newline at end of file
index 46ae707e6be3579dba373853da1ec152586703d5..33c8cfeffc5702b005d18fc2b19cca46c8ab2171 100644 (file)
@@ -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<NCSIZE-1; i++){
-    if( mem.sizeCnt[i] ){
-      fprintf(out, "   %3d: %d\n", i*8+8, mem.sizeCnt[i]);
+    if( mem.nAlloc[i] ){
+      fprintf(out, "   %5d: %10d %10d %10d\n", 
+            i*8, mem.nAlloc[i], mem.nCurrent[i], mem.mxCurrent[i]);
     }
   }
-  if( mem.sizeCnt[NCSIZE-1] ){
-    fprintf(out, "  >%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<NCSIZE; i++){
-    nTotal += mem.sizeCnt[i];
+    nTotal += mem.nAlloc[i];
   }
   return nTotal;
 }
index 8b6ab9d4c620f9f9d3846b27dc92c85581f04589..dcee0733a74100de0c892e4ba2345eada30c1fc1 100644 (file)
 # This file implements regression tests for SQLite library.  The
 # focus of this script is measuring executing speed.
 #
-# $Id: speed1.test,v 1.5 2007/03/31 22:34:16 drh Exp $
+# $Id: speed1.test,v 1.6 2008/07/24 23:34:07 drh Exp $
 #
 
+sqlite3_shutdown
+sqlite3_config_scratch 29000 1
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
 speed_trial_init speed1
index 5abf236ae7d91f009a44e16df58f1aaca4456ff6..8ece209dde8085cad6b37141dbc0d5e41e0f2f1b 100644 (file)
 #
 # This is a copy of speed1.test modified to user prepared statements.
 #
-# $Id: speed1p.test,v 1.2 2008/04/03 19:40:59 drh Exp $
+# $Id: speed1p.test,v 1.3 2008/07/24 23:34:07 drh Exp $
 #
 
+sqlite3_shutdown
+sqlite3_config_scratch 29000 1
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
 speed_trial_init speed1
index 0992ecef0f84790949b3c1c815a4936f4beddc56..c10f3d5fb4854e2ea8115e15b0b9d3f0a08344c5 100644 (file)
@@ -143,11 +143,11 @@ static const YYCODETYPE yyFallback[] = {
 **      It is sometimes called the "minor" token.
 */
 struct yyStackEntry {
-  int stateno;       /* The state-number */
-  int major;         /* The major token value.  This is the code
-                     ** number for the token at this stack level */
-  YYMINORTYPE minor; /* The user-supplied minor token value.  This
-                     ** is the value of the token  */
+  YYACTIONTYPE stateno;  /* The state-number */
+  YYCODETYPE major;      /* The major token value.  This is the code
+                         ** number for the token at this stack level */
+  YYMINORTYPE minor;     /* The user-supplied minor token value.  This
+                         ** is the value of the token  */
 };
 typedef struct yyStackEntry yyStackEntry;