/ Check-in [ce075085]
Login

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

Overview
Comment:Speed up releaseMemArray() a bit by handling the most common types of memory cells inline. (CVS 5726)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ce07508550da858beb0bc0763c65e6d556bb0843
User & Date: danielk1977 2008-09-19 18:32:27
Context
2008-09-21
15:14
Give file scope to non-API routines in pcache. Ticket #3392. (CVS 5727) check-in: 6521f98a user: drh tags: trunk
2008-09-19
18:32
Speed up releaseMemArray() a bit by handling the most common types of memory cells inline. (CVS 5726) check-in: ce075085 user: danielk1977 tags: trunk
16:39
In function moveToRoot(), use the MemPage.pParent pointers to find the root page if they are valid. This is slightly faster than requesting a new reference to the root page from the pager layer. (CVS 5725) check-in: 0c8b74e6 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbeaux.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used for creating, destroying, and populating
    13     13   ** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.)  Prior
    14     14   ** to version 2.8.7, all this code was combined into the vdbe.c source file.
    15     15   ** But that file was getting too big so this subroutines were split out.
    16     16   **
    17         -** $Id: vdbeaux.c,v 1.410 2008/09/16 09:09:20 danielk1977 Exp $
           17  +** $Id: vdbeaux.c,v 1.411 2008/09/19 18:32:27 danielk1977 Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include <ctype.h>
    21     21   #include "vdbeInt.h"
    22     22   
    23     23   
    24     24   
................................................................................
   757    757   #endif
   758    758   
   759    759   /*
   760    760   ** Release an array of N Mem elements
   761    761   */
   762    762   static void releaseMemArray(Mem *p, int N){
   763    763     if( p && N ){
          764  +    Mem *pEnd;
   764    765       sqlite3 *db = p->db;
   765    766       int malloc_failed = db->mallocFailed;
   766         -    while( N-->0 ){
   767         -      assert( N<2 || p[0].db==p[1].db );
   768         -      sqlite3VdbeMemRelease(p);
          767  +    for(pEnd=&p[N]; p<pEnd; p++){
          768  +      assert( (&p[1])==pEnd || p[0].db==p[1].db );
          769  +
          770  +      /* This block is really an inlined version of sqlite3VdbeMemRelease()
          771  +      ** that takes advantage of the fact that the memory cell value is 
          772  +      ** being set to NULL after releasing any dynamic resources.
          773  +      **
          774  +      ** The justification for duplicating code is that according to 
          775  +      ** callgrind, this causes a certain test case to hit the CPU 4.7 
          776  +      ** percent less (x86 linux, gcc version 4.1.2, -O6) than if 
          777  +      ** sqlite3MemRelease() were called from here. With -O2, this jumps
          778  +      ** to 6.6 percent. The test case is inserting 1000 rows into a table 
          779  +      ** with no indexes using a single prepared INSERT statement, bind() 
          780  +      ** and reset(). Inserts are grouped into a transaction.
          781  +      */
          782  +      if( p->flags&(MEM_Agg|MEM_Dyn) ){
          783  +        sqlite3VdbeMemRelease(p);
          784  +      }else if( p->zMalloc ){
          785  +        sqlite3DbFree(db, p->zMalloc);
          786  +        p->zMalloc = 0;
          787  +      }
          788  +
   769    789         p->flags = MEM_Null;
   770         -      p++;
   771    790       }
   772    791       db->mallocFailed = malloc_failed;
   773    792     }
   774    793   }
   775    794   
   776    795   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
   777    796   int sqlite3VdbeReleaseBuffers(Vdbe *p){