/ Check-in [e3840fbf]
Login

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

Overview
Comment:Pick up a small performance increase by eliminating the pcacheRef() function. (CVS 5609)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e3840fbf0adf824941a4b9b3cac3a869f195d6f8
User & Date: danielk1977 2008-08-25 14:49:42
Context
2008-08-25
17:23
Fix bug in the premutation testing that was causing many permutations from begin skipped. There are now 16 errors reported by the permutation test. (CVS 5610) check-in: 4ad096bd user: drh tags: trunk
14:49
Pick up a small performance increase by eliminating the pcacheRef() function. (CVS 5609) check-in: e3840fbf user: danielk1977 tags: trunk
12:14
Additional coverage testing in the new name resolver module. (CVS 5608) check-in: 0d61960a user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pcache.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file implements that page cache.
    13     13   **
    14         -** @(#) $Id: pcache.c,v 1.12 2008/08/25 07:12:29 danielk1977 Exp $
           14  +** @(#) $Id: pcache.c,v 1.13 2008/08/25 14:49:42 danielk1977 Exp $
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   
    18     18   /*
    19     19   ** A complete page cache is an instance of this structure.
    20     20   */
    21     21   struct PCache {
................................................................................
   107    107   ** Deadlock within the module is avoided by never blocking on the MEM2 
   108    108   ** mutex while the LRU mutex is held.
   109    109   */
   110    110   
   111    111   #define pcacheEnterGlobal() sqlite3_mutex_enter(pcache.mutex_lru)
   112    112   #define pcacheExitGlobal()  sqlite3_mutex_leave(pcache.mutex_lru)
   113    113   
   114         -/*
   115         -** Increment the reference count on both page p and its cache by n.
   116         -*/
   117         -static void pcacheRef(PgHdr *p, int n){
   118         -  /* This next block assert()s that the number of references to the 
   119         -  ** PCache is the sum of the number of references to all pages in
   120         -  ** the PCache. This is a bit expensive to leave turned on all the 
   121         -  ** time, even in debugging builds.
   122         -  */
   123         -#if 0
   124         -  PgHdr *pHdr;
   125         -  int nRef = 0;
   126         -  for(pHdr=p->pCache->pClean; pHdr; pHdr=pHdr->pNext) nRef += pHdr->nRef;
   127         -  for(pHdr=p->pCache->pDirty; pHdr; pHdr=pHdr->pNext) nRef += pHdr->nRef;
   128         -  assert( p->pCache->nRef==nRef );
   129         -#endif
   130         -  p->nRef += n;
   131         -  p->pCache->nRef += n;
   132         -}
   133         -
   134    114   /********************************** Linked List Management ********************/
   135    115   
   136    116   #ifndef NDEBUG
   137    117   /*
   138    118   ** This routine verifies that the number of entries in the hash table
   139    119   ** is pCache->nPage.  This routine is used within assert() statements
   140    120   ** only and is therefore disabled during production builds.
................................................................................
   654    634       for(pPage=pCache->apHash[h]; pPage; pPage=pPage->pNextHash){
   655    635         if( pPage->pgno==pgno ){
   656    636           if( pPage->nRef==0 /* && (pPage->flags & PGHDR_DIRTY)==0 */ ){
   657    637             pcacheEnterGlobal();
   658    638             pcacheRemoveFromLruList(pPage);
   659    639             pcacheExitGlobal();
   660    640           }
   661         -        pcacheRef(pPage, 1);
          641  +        if( (pPage->nRef++)==0 ){
          642  +          pCache->nRef++;
          643  +        }
   662    644           *ppPage = pPage;
   663    645           return SQLITE_OK;
   664    646         }
   665    647       }
   666    648     }
   667    649   
   668    650     if( createFlag ){
................................................................................
   678    660       if( pPage==0 ){
   679    661         return SQLITE_NOMEM;
   680    662       }
   681    663   
   682    664       pPage->pPager = 0;
   683    665       pPage->flags = 0;
   684    666       pPage->pDirty = 0;
   685         -    pPage->nRef = 0;
   686    667       pPage->pgno = pgno;
   687    668       pPage->pCache = pCache;
   688         -    pcacheRef(pPage, 1);
          669  +    pPage->nRef = 1;
          670  +    pCache->nRef++;
   689    671       pcacheAddToList(&pCache->pClean, pPage);
   690    672       pcacheAddToHash(pPage);
   691    673     }else{
   692    674       *ppPage = 0;
   693    675     }
   694    676   
   695    677     return SQLITE_OK;
................................................................................
   698    680   /*
   699    681   ** Dereference a page.  When the reference count reaches zero,
   700    682   ** move the page to the LRU list if it is clean.
   701    683   */
   702    684   void sqlite3PcacheRelease(PgHdr *p){
   703    685     assert( p->nRef>0 );
   704    686     assert( p->pCache->iInUseDB || p->pCache->iInUseMM );
   705         -  pcacheRef(p, -1);
   706         -  if( p->nRef!=0 ) return;
   707         -  if( p->pCache->xDestroy ){
   708         -    p->pCache->xDestroy(p);
   709         -  }
          687  +  p->nRef--;
          688  +  if( p->nRef==0 ){
          689  +    PCache *pCache = p->pCache;
          690  +    pCache->nRef--;
          691  +    if( p->pCache->xDestroy ){
          692  +      p->pCache->xDestroy(p);
          693  +    }
   710    694   #if 0
   711         -  if( (p->flags & PGHDR_DIRTY)!=0 ) return;
          695  +    if( (p->flags & PGHDR_DIRTY)!=0 ) return;
   712    696   #endif
   713         -  pcacheEnterGlobal();
   714         -  pcacheAddToLruList(p);
   715         -  pcacheExitGlobal();
          697  +    pcacheEnterGlobal();
          698  +    pcacheAddToLruList(p);
          699  +    pcacheExitGlobal();
          700  +  }
   716    701   }
   717    702   
   718    703   void sqlite3PcacheRef(PgHdr *p){
   719         -  assert(p->nRef>=0);
   720         -  pcacheRef(p, 1);
          704  +  assert(p->nRef>0);
          705  +  p->nRef++;
   721    706   }
   722    707   
   723    708   /*
   724    709   ** Drop a page from the cache.  This should be the only reference to
   725    710   ** the page.
   726    711   */
   727    712   void sqlite3PcacheDrop(PgHdr *p){