/ Check-in [6422d223]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Change sqlite3StatusSet() into sqlite3StatusHighwater() so that only the highwater mark is recorded. This gives a small size reduction and performance improvement.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:6422d223dd10018703c6b083d29a3c35c837fc97
User & Date: drh 2015-10-15 15:28:56
Context
2015-10-15
16:20
Performance optimizations to the sqlite3MallocSize() by requiring the argument to always be non-NULL. check-in: cb65989b user: drh tags: trunk
15:28
Change sqlite3StatusSet() into sqlite3StatusHighwater() so that only the highwater mark is recorded. This gives a small size reduction and performance improvement. check-in: 6422d223 user: drh tags: trunk
12:06
Make sure sqlite.h is not #included by itself. check-in: a61880c2 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/malloc.c.

   220    220   ** lock is already held.
   221    221   */
   222    222   static int mallocWithAlarm(int n, void **pp){
   223    223     int nFull;
   224    224     void *p;
   225    225     assert( sqlite3_mutex_held(mem0.mutex) );
   226    226     nFull = sqlite3GlobalConfig.m.xRoundup(n);
   227         -  sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n);
          227  +  sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n);
   228    228     if( mem0.alarmThreshold>0 ){
   229    229       sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
   230    230       if( nUsed >= mem0.alarmThreshold - nFull ){
   231    231         mem0.nearlyFull = 1;
   232    232         sqlite3MallocAlarm(nFull);
   233    233       }else{
   234    234         mem0.nearlyFull = 0;
................................................................................
   312    312   ** embedded processor.
   313    313   */
   314    314   void *sqlite3ScratchMalloc(int n){
   315    315     void *p;
   316    316     assert( n>0 );
   317    317   
   318    318     sqlite3_mutex_enter(mem0.mutex);
   319         -  sqlite3StatusSet(SQLITE_STATUS_SCRATCH_SIZE, n);
          319  +  sqlite3StatusHighwater(SQLITE_STATUS_SCRATCH_SIZE, n);
   320    320     if( mem0.nScratchFree && sqlite3GlobalConfig.szScratch>=n ){
   321    321       p = mem0.pScratchFree;
   322    322       mem0.pScratchFree = mem0.pScratchFree->pNext;
   323    323       mem0.nScratchFree--;
   324    324       sqlite3StatusUp(SQLITE_STATUS_SCRATCH_USED, 1);
   325    325       sqlite3_mutex_leave(mem0.mutex);
   326    326     }else{
................................................................................
   514    514     ** argument to xRealloc is always a value returned by a prior call to
   515    515     ** xRoundup. */
   516    516     nNew = sqlite3GlobalConfig.m.xRoundup((int)nBytes);
   517    517     if( nOld==nNew ){
   518    518       pNew = pOld;
   519    519     }else if( sqlite3GlobalConfig.bMemstat ){
   520    520       sqlite3_mutex_enter(mem0.mutex);
   521         -    sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, (int)nBytes);
          521  +    sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, (int)nBytes);
   522    522       nDiff = nNew - nOld;
   523    523       if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= 
   524    524             mem0.alarmThreshold-nDiff ){
   525    525         sqlite3MallocAlarm(nDiff);
   526    526       }
   527    527       pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
   528    528       if( pNew==0 && mem0.alarmThreshold>0 ){

Changes to src/pcache1.c.

   316    316       sqlite3_mutex_enter(pcache1.mutex);
   317    317       p = (PgHdr1 *)pcache1.pFree;
   318    318       if( p ){
   319    319         pcache1.pFree = pcache1.pFree->pNext;
   320    320         pcache1.nFreeSlot--;
   321    321         pcache1.bUnderPressure = pcache1.nFreeSlot<pcache1.nReserve;
   322    322         assert( pcache1.nFreeSlot>=0 );
   323         -      sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
          323  +      sqlite3StatusHighwater(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
   324    324         sqlite3StatusUp(SQLITE_STATUS_PAGECACHE_USED, 1);
   325    325       }
   326    326       sqlite3_mutex_leave(pcache1.mutex);
   327    327     }
   328    328     if( p==0 ){
   329    329       /* Memory is not available in the SQLITE_CONFIG_PAGECACHE pool.  Get
   330    330       ** it from sqlite3Malloc instead.
   331    331       */
   332    332       p = sqlite3Malloc(nByte);
   333    333   #ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
   334    334       if( p ){
   335    335         int sz = sqlite3MallocSize(p);
   336    336         sqlite3_mutex_enter(pcache1.mutex);
   337         -      sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
          337  +      sqlite3StatusHighwater(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
   338    338         sqlite3StatusUp(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
   339    339         sqlite3_mutex_leave(pcache1.mutex);
   340    340       }
   341    341   #endif
   342    342       sqlite3MemdebugSetType(p, MEMTYPE_PCACHE);
   343    343     }
   344    344     return p;

Changes to src/sqlite.h.in.

  6568   6568   ** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
  6569   6569   ** <dd>This parameter records the largest memory allocation request
  6570   6570   ** handed to [scratch memory allocator].  Only the value returned in the
  6571   6571   ** *pHighwater parameter to [sqlite3_status()] is of interest.  
  6572   6572   ** The value written into the *pCurrent parameter is undefined.</dd>)^
  6573   6573   **
  6574   6574   ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
  6575         -** <dd>This parameter records the deepest parser stack.  It is only
         6575  +** <dd>The *pHighwater parameter records the deepest parser stack. 
         6576  +** The *pCurrent value is undefined.  The *pHighwater value is only
  6576   6577   ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
  6577   6578   ** </dl>
  6578   6579   **
  6579   6580   ** New status parameters may be added from time to time.
  6580   6581   */
  6581   6582   #define SQLITE_STATUS_MEMORY_USED          0
  6582   6583   #define SQLITE_STATUS_PAGECACHE_USED       1

Changes to src/sqliteInt.h.

  3205   3205   #else
  3206   3206   # define sqlite3MemoryBarrier()
  3207   3207   #endif
  3208   3208   
  3209   3209   sqlite3_int64 sqlite3StatusValue(int);
  3210   3210   void sqlite3StatusUp(int, int);
  3211   3211   void sqlite3StatusDown(int, int);
  3212         -void sqlite3StatusSet(int, int);
         3212  +void sqlite3StatusHighwater(int, int);
  3213   3213   
  3214   3214   /* Access to mutexes used by sqlite3_status() */
  3215   3215   sqlite3_mutex *sqlite3Pcache1Mutex(void);
  3216   3216   sqlite3_mutex *sqlite3MallocMutex(void);
  3217   3217   
  3218   3218   #ifndef SQLITE_OMIT_FLOATING_POINT
  3219   3219     int sqlite3IsNaN(double);

Changes to src/status.c.

   104    104     assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex()
   105    105                                              : sqlite3MallocMutex()) );
   106    106     assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
   107    107     wsdStat.nowValue[op] -= N;
   108    108   }
   109    109   
   110    110   /*
   111         -** Set the value of a status to X.  The highwater mark is adjusted if
   112         -** necessary.  The caller must hold the appropriate mutex.
          111  +** Adjust the highwater mark if necessary.
          112  +** The caller must hold the appropriate mutex.
   113    113   */
   114         -void sqlite3StatusSet(int op, int X){
          114  +void sqlite3StatusHighwater(int op, int X){
   115    115     wsdStatInit;
   116    116     assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
   117    117     assert( op>=0 && op<ArraySize(statMutex) );
   118    118     assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex()
   119    119                                              : sqlite3MallocMutex()) );
   120         -  wsdStat.nowValue[op] = X;
   121         -  if( wsdStat.nowValue[op]>wsdStat.mxValue[op] ){
   122         -    wsdStat.mxValue[op] = wsdStat.nowValue[op];
          120  +  assert( op==SQLITE_STATUS_MALLOC_SIZE
          121  +          || op==SQLITE_STATUS_PAGECACHE_SIZE
          122  +          || op==SQLITE_STATUS_SCRATCH_SIZE
          123  +          || op==SQLITE_STATUS_PARSER_STACK );
          124  +  if( X>wsdStat.mxValue[op] ){
          125  +    wsdStat.mxValue[op] = X;
   123    126     }
   124    127   }
   125    128   
   126    129   /*
   127    130   ** Query status information.
   128    131   */
   129    132   int sqlite3_status64(

Changes to src/tokenize.c.

   463    463       }
   464    464       if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
   465    465         sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
   466    466       }
   467    467     }
   468    468   #ifdef YYTRACKMAXSTACKDEPTH
   469    469     sqlite3_mutex_enter(sqlite3MallocMutex());
   470         -  sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK,
          470  +  sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
   471    471         sqlite3ParserStackPeak(pEngine)
   472    472     );
   473    473     sqlite3_mutex_leave(sqlite3MallocMutex());
   474    474   #endif /* YYDEBUG */
   475    475     sqlite3ParserFree(pEngine, sqlite3_free);
   476    476     db->lookaside.bEnabled = enableLookaside;
   477    477     if( db->mallocFailed ){