/ Check-in [897f56a1]
Login

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

Overview
Comment:Performance improvements on memory copies inside of btree by moving 2 bytes at a time instead of just 1 byte at a time.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 897f56a158ebe62758c9998e4941ae046c75fb99
User & Date: drh 2011-06-03 23:28:33
References
2011-06-06
13:38
Add assert() statements to verify that u16 pointers associated with the enhancement in [897f56a158] are always 2-byte aligned. check-in: 98ccfa93 user: drh tags: trunk
Context
2011-06-04
01:43
Performance improvement to the btree search routine. check-in: 65db822f user: drh tags: trunk
2011-06-03
23:28
Performance improvements on memory copies inside of btree by moving 2 bytes at a time instead of just 1 byte at a time. check-in: 897f56a1 user: drh tags: trunk
21:34
Performance enhancement to the blob-literal tokenizer. check-in: 61aa2031 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  5418   5418     rc = freeSpace(pPage, pc, sz);
  5419   5419     if( rc ){
  5420   5420       *pRC = rc;
  5421   5421       return;
  5422   5422     }
  5423   5423     endPtr = &data[pPage->cellOffset + 2*pPage->nCell - 2];
  5424   5424     while( ptr<endPtr ){
  5425         -    ptr[0] = ptr[2];
  5426         -    ptr[1] = ptr[3];
         5425  +    *(u16*)ptr = *(u16*)&ptr[2];
  5427   5426       ptr += 2;
  5428   5427     }
  5429   5428     pPage->nCell--;
  5430   5429     put2byte(&data[hdr+3], pPage->nCell);
  5431   5430     pPage->nFree += 2;
  5432   5431   }
  5433   5432   
................................................................................
  5460   5459     int idx = 0;      /* Where to write new cell content in data[] */
  5461   5460     int j;            /* Loop counter */
  5462   5461     int end;          /* First byte past the last cell pointer in data[] */
  5463   5462     int ins;          /* Index in data[] where new cell pointer is inserted */
  5464   5463     int cellOffset;   /* Address of first cell pointer in data[] */
  5465   5464     u8 *data;         /* The content of the whole page */
  5466   5465     u8 *ptr;          /* Used for moving information around in data[] */
         5466  +  u8 *endPtr;       /* End of the loop */
  5467   5467   
  5468   5468     int nSkip = (iChild ? 4 : 0);
  5469   5469   
  5470   5470     if( *pRC ) return;
  5471   5471   
  5472   5472     assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
  5473   5473     assert( pPage->nCell<=MX_CELL(pPage->pBt) && MX_CELL(pPage->pBt)<=10921 );
................................................................................
  5510   5510       assert( idx+sz <= (int)pPage->pBt->usableSize );
  5511   5511       pPage->nCell++;
  5512   5512       pPage->nFree -= (u16)(2 + sz);
  5513   5513       memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip);
  5514   5514       if( iChild ){
  5515   5515         put4byte(&data[idx], iChild);
  5516   5516       }
  5517         -    for(j=end, ptr=&data[j]; j>ins; j-=2, ptr-=2){
  5518         -      ptr[0] = ptr[-2];
  5519         -      ptr[1] = ptr[-1];
         5517  +    ptr = &data[end];
         5518  +    endPtr = &data[ins];
         5519  +    while( ptr>endPtr ){
         5520  +      *(u16*)ptr = *(u16*)&ptr[-2];
         5521  +      ptr -= 2;
  5520   5522       }
  5521   5523       put2byte(&data[ins], idx);
  5522   5524       put2byte(&data[pPage->hdrOffset+3], pPage->nCell);
  5523   5525   #ifndef SQLITE_OMIT_AUTOVACUUM
  5524   5526       if( pPage->pBt->autoVacuum ){
  5525   5527         /* The cell may contain a pointer to an overflow page. If so, write
  5526   5528         ** the entry for the overflow page into the pointer map.
................................................................................
  5557   5559     /* Check that the page has just been zeroed by zeroPage() */
  5558   5560     assert( pPage->nCell==0 );
  5559   5561     assert( get2byteNotZero(&data[hdr+5])==nUsable );
  5560   5562   
  5561   5563     pCellptr = &data[pPage->cellOffset + nCell*2];
  5562   5564     cellbody = nUsable;
  5563   5565     for(i=nCell-1; i>=0; i--){
         5566  +    u16 sz = aSize[i];
  5564   5567       pCellptr -= 2;
  5565         -    cellbody -= aSize[i];
         5568  +    cellbody -= sz;
  5566   5569       put2byte(pCellptr, cellbody);
  5567         -    memcpy(&data[cellbody], apCell[i], aSize[i]);
         5570  +    memcpy(&data[cellbody], apCell[i], sz);
  5568   5571     }
  5569   5572     put2byte(&data[hdr+3], nCell);
  5570   5573     put2byte(&data[hdr+5], cellbody);
  5571   5574     pPage->nFree -= (nCell*2 + nUsable - cellbody);
  5572   5575     pPage->nCell = (u16)nCell;
  5573   5576   }
  5574   5577