/ Check-in [85940468]
Login

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

Overview
Comment:Performance improvement by avoiding unnecessary calls to memset().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 85940468e6f93f7c493fbc129f13cf6233c5d0c0
User & Date: drh 2009-11-18 23:01:26
Context
2009-11-19
14:52
Merge the fts3-refactor branch with the trunk. check-in: c8d2bd37 user: dan tags: fts3-refactor
14:48
Fix a bug introduced with recent optimizations: The unary minus operator is TK_UMINUS, not TK_MINUS. check-in: 4bd43307 user: drh tags: trunk
2009-11-18
23:01
Performance improvement by avoiding unnecessary calls to memset(). check-in: 85940468 user: drh tags: trunk
01:25
Suppress more instances of unnecessary OP_IsNull and OP_Affinity opcodes. check-in: bf6c0bd1 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  3274   3274   **
  3275   3275   ** 4:  There must be an active transaction.
  3276   3276   **
  3277   3277   ** No checking is done to make sure that page iTable really is the
  3278   3278   ** root page of a b-tree.  If it is not, then the cursor acquired
  3279   3279   ** will not work correctly.
  3280   3280   **
  3281         -** It is assumed that the sqlite3BtreeCursorSize() bytes of memory 
  3282         -** pointed to by pCur have been zeroed by the caller.
         3281  +** It is assumed that the sqlite3BtreeCursorZero() has been called
         3282  +** on pCur to initialize the memory space prior to invoking this routine.
  3283   3283   */
  3284   3284   static int btreeCursor(
  3285   3285     Btree *p,                              /* The btree */
  3286   3286     int iTable,                            /* Root page of table to open */
  3287   3287     int wrFlag,                            /* 1 to write. 0 read-only */
  3288   3288     struct KeyInfo *pKeyInfo,              /* First arg to comparison function */
  3289   3289     BtCursor *pCur                         /* Space for new cursor */
................................................................................
  3350   3350   ** sufficient storage to hold a cursor.  The BtCursor object is opaque
  3351   3351   ** to users so they cannot do the sizeof() themselves - they must call
  3352   3352   ** this routine.
  3353   3353   */
  3354   3354   int sqlite3BtreeCursorSize(void){
  3355   3355     return ROUND8(sizeof(BtCursor));
  3356   3356   }
         3357  +
         3358  +/*
         3359  +** Initialize memory that will be converted into a BtCursor object.
         3360  +**
         3361  +** The simple approach here would be to memset() the entire object
         3362  +** to zero.  But it turns out that the apPage[] and aiIdx[] arrays
         3363  +** do not need to be zeroed and they are large, so we can save a lot
         3364  +** of run-time by skipping the initialization of those elements.
         3365  +*/
         3366  +void sqlite3BtreeCursorZero(BtCursor *p){
         3367  +  memset(p, 0, offsetof(BtCursor, iPage));
         3368  +}
  3357   3369   
  3358   3370   /*
  3359   3371   ** Set the cached rowid value of every cursor in the same database file
  3360   3372   ** as pCur and having the same root page number as pCur.  The value is
  3361   3373   ** set to iRowid.
  3362   3374   **
  3363   3375   ** Only positive rowid values are considered valid for this cache.

Changes to src/btree.h.

   144    144     Btree*,                              /* BTree containing table to open */
   145    145     int iTable,                          /* Index of root page */
   146    146     int wrFlag,                          /* 1 for writing.  0 for read-only */
   147    147     struct KeyInfo*,                     /* First argument to compare function */
   148    148     BtCursor *pCursor                    /* Space to write cursor structure */
   149    149   );
   150    150   int sqlite3BtreeCursorSize(void);
          151  +void sqlite3BtreeCursorZero(BtCursor*);
   151    152   
   152    153   int sqlite3BtreeCloseCursor(BtCursor*);
   153    154   int sqlite3BtreeMovetoUnpacked(
   154    155     BtCursor*,
   155    156     UnpackedRecord *pUnKey,
   156    157     i64 intKey,
   157    158     int bias,

Changes to src/vdbe.c.

   211    211     assert( iCur<p->nCursor );
   212    212     if( p->apCsr[iCur] ){
   213    213       sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
   214    214       p->apCsr[iCur] = 0;
   215    215     }
   216    216     if( SQLITE_OK==sqlite3VdbeMemGrow(pMem, nByte, 0) ){
   217    217       p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
   218         -    memset(pCx, 0, nByte);
          218  +    memset(pCx, 0, sizeof(VdbeCursor));
   219    219       pCx->iDb = iDb;
   220    220       pCx->nField = nField;
   221    221       if( nField ){
   222    222         pCx->aType = (u32 *)&pMem->z[ROUND8(sizeof(VdbeCursor))];
   223    223       }
   224    224       if( isBtreeCursor ){
   225    225         pCx->pCursor = (BtCursor*)
   226    226             &pMem->z[ROUND8(sizeof(VdbeCursor))+2*nField*sizeof(u32)];
          227  +      sqlite3BtreeCursorZero(pCx->pCursor);
   227    228       }
   228    229     }
   229    230     return pCx;
   230    231   }
   231    232   
   232    233   /*
   233    234   ** Try to convert a value into a numeric representation if we can