From e1fd508a28b3c8b385b2ed70e8412e6146725bc8 Mon Sep 17 00:00:00 2001 From: danielk1977 Date: Fri, 23 Jan 2009 16:45:00 +0000 Subject: [PATCH] Optimization: When loading a new page into the cache, avoid redundant memset() calls to zero it. (CVS 6201) FossilOrigin-Name: 9c0b9f881367871105965d4268e2f2cde7f4d884 --- manifest | 22 +++++++++++----------- manifest.uuid | 2 +- src/pager.c | 7 ++++--- src/pager.h | 4 ++-- src/pcache.c | 17 ++++++++++++----- src/pcache1.c | 7 ++++--- src/sqlite.h.in | 16 ++++++++-------- 7 files changed, 42 insertions(+), 33 deletions(-) diff --git a/manifest b/manifest index e118ef53d3..9961687ba9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sVACUUM\scommand\sso\sthat\sit\sdoes\snot\scommit\sa\stransaction\swhen\sit\sis\nmistakenly\srun\swithin\sa\stransaction\s-\sit\sshould\sleave\sthe\stransaction\sopen.\s(CVS\s6200) -D 2009-01-22T23:04:46 +C Optimization:\sWhen\sloading\sa\snew\spage\sinto\sthe\scache,\savoid\sredundant\smemset()\scalls\sto\szero\sit.\s(CVS\s6201) +D 2009-01-23T16:45:01 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 6619a1b72de7ada2bb7be97862913e27c6f5e339 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -142,12 +142,12 @@ F src/os_common.h 24525d8b7bce66c374dfc1810a6c9043f3359b60 F src/os_os2.c bed77dc26e3a95ce4a204936b9a1ca6fe612fcc5 F src/os_unix.c c74255cc1fcddc38fc3cc1dcf70c2325d3c2948e F src/os_win.c 496e3ceb499aedc63622a89ef76f7af2dd902709 -F src/pager.c ce7118d56c653c71d6d283006453e49e5bff8b10 -F src/pager.h 95b9802f6a014cc55523006f2b893a37b2dc16e3 +F src/pager.c be92682af31f44f41c9947f174c5f811648ec68c +F src/pager.h 869b7027b031e30da24ebe9bdb973d1ec673a96b F src/parse.y b214295a91e985c42adb6bfd3ad1c56c47828e8d -F src/pcache.c 48fbfc2208a2734c578b3223fcd4fea7d84f442b +F src/pcache.c fcf7738c83c4d3e9d45836b2334c8a368cc41274 F src/pcache.h 9b927ccc5a538e31b4c3bc7eec4f976db42a1324 -F src/pcache1.c c0aa84ff69ea759fa944dbee9167a2463ab7c322 +F src/pcache1.c dabb8ab14827e090321f17150ce96fda172974e8 F src/pragma.c 04c13c79fd559d769f5bcb3aa661b32d484b1e7b F src/prepare.c 9ec504ddd4a8e34e5fb502033312da6a78f5f76a F src/printf.c 9866a9a9c4a90f6d4147407f373df3fd5d5f9b6f @@ -156,7 +156,7 @@ F src/resolve.c 18dc9f0df1d60048e012ce6632251063e0dd356a F src/rowset.c ba9375f37053d422dd76965a9c370a13b6e1aac4 F src/select.c ae72b604e47092521c4d9ae54e1b1cbeb872a747 F src/shell.c 0d801ef653fd73d17161afebaab898a58ec3524b -F src/sqlite.h.in 6cd2489e40fe97ba58c60044a4ced377e08b6d09 +F src/sqlite.h.in 8821a61dceff26993ed6689239b6fbcd8d8f6e50 F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17 F src/sqliteInt.h 086886697368982dd7469689cd6e96c94d091008 F src/sqliteLimit.h ffe93f5a0c4e7bd13e70cd7bf84cfb5c3465f45d @@ -697,7 +697,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P 78ae96def54026461c0d03a90394480f724ea584 -R b9c2aadad22cb62a07734ad4365fba0e -U drh -Z 23b2dc2d7661a21482fba1cdc855f298 +P 75cc709be46ae2096d2ba3e7ac58de8140f8130c +R 8b23ab517890ddeec94bfd9db73627da +U danielk1977 +Z 5750c0351bde53b3891c00b777a3ffd1 diff --git a/manifest.uuid b/manifest.uuid index e4c6427881..4db924d03e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -75cc709be46ae2096d2ba3e7ac58de8140f8130c \ No newline at end of file +9c0b9f881367871105965d4268e2f2cde7f4d884 \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index c81b636d27..5d15763bbe 100644 --- a/src/pager.c +++ b/src/pager.c @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.557 2009/01/22 17:12:40 danielk1977 Exp $ +** @(#) $Id: pager.c,v 1.558 2009/01/23 16:45:01 danielk1977 Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -3730,6 +3730,7 @@ int sqlite3PagerAcquire( return rc; } assert( pPg->pgno==pgno ); + assert( pPg->pPager==pPager || pPg->pPager==0 ); if( pPg->pPager==0 ){ /* The pager cache has created a new page. Its content needs to ** be initialized. @@ -3737,7 +3738,6 @@ int sqlite3PagerAcquire( int nMax; PAGER_INCR(pPager->nMiss); pPg->pPager = pPager; - memset(pPg->pExtra, 0, pPager->nExtra); rc = sqlite3PagerPagecount(pPager, &nMax); if( rc!=SQLITE_OK ){ @@ -3750,7 +3750,6 @@ int sqlite3PagerAcquire( sqlite3PagerUnref(pPg); return SQLITE_FULL; } - memset(pPg->pData, 0, pPager->pageSize); if( noContent ){ /* Failure to set the bits in the InJournal bit-vectors is benign. ** It merely means that we might do some extra work to journal a @@ -3766,6 +3765,8 @@ int sqlite3PagerAcquire( TESTONLY( rc = ) addToSavepointBitvecs(pPager, pgno); testcase( rc==SQLITE_NOMEM ); sqlite3EndBenignMalloc(); + }else{ + memset(pPg->pData, 0, pPager->pageSize); } IOTRACE(("ZERO %p %d\n", pPager, pgno)); }else{ diff --git a/src/pager.h b/src/pager.h index 6fdaccfeb6..1049eb8531 100644 --- a/src/pager.h +++ b/src/pager.h @@ -13,7 +13,7 @@ ** subsystem. The page cache subsystem reads and writes a file a page ** at a time and provides a journal for rollback. ** -** @(#) $Id: pager.h,v 1.96 2009/01/20 17:06:27 danielk1977 Exp $ +** @(#) $Id: pager.h,v 1.97 2009/01/23 16:45:01 danielk1977 Exp $ */ #ifndef _PAGER_H_ @@ -88,13 +88,13 @@ typedef struct PgHdr DbPage; /* Open and close a Pager connection. */ int sqlite3PagerOpen(sqlite3_vfs *, Pager **ppPager, const char*, int,int,int); int sqlite3PagerClose(Pager *pPager); +int sqlite3PagerReadFileheader(Pager*, int, unsigned char*); /* Functions used to configure a Pager object. */ void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *); void sqlite3PagerSetReiniter(Pager*, void(*)(DbPage*)); int sqlite3PagerSetPagesize(Pager*, u16*); int sqlite3PagerMaxPageCount(Pager*, int); -int sqlite3PagerReadFileheader(Pager*, int, unsigned char*); void sqlite3PagerSetCachesize(Pager*, int); void sqlite3PagerSetSafetyLevel(Pager*,int,int); int sqlite3PagerLockingMode(Pager *, int); diff --git a/src/pcache.c b/src/pcache.c index 4065a54f4b..26d9c8206b 100644 --- a/src/pcache.c +++ b/src/pcache.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file implements that page cache. ** -** @(#) $Id: pcache.c,v 1.42 2009/01/20 17:06:27 danielk1977 Exp $ +** @(#) $Id: pcache.c,v 1.43 2009/01/23 16:45:01 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -261,14 +261,21 @@ int sqlite3PcacheFetch( } if( pPage ){ + if( !pPage->pData ){ + memset(pPage, 0, sizeof(PgHdr) + pCache->szExtra); + pPage->pExtra = (void*)&pPage[1]; + pPage->pData = (void *)&((char *)pPage)[sizeof(PgHdr) + pCache->szExtra]; + pPage->pCache = pCache; + pPage->pgno = pgno; + } + assert( pPage->pCache==pCache ); + assert( pPage->pgno==pgno ); + assert( pPage->pExtra==(void *)&pPage[1] ); + if( 0==pPage->nRef ){ pCache->nRef++; } pPage->nRef++; - pPage->pData = (void*)&pPage[1]; - pPage->pExtra = (void*)&((char*)pPage->pData)[pCache->szPage]; - pPage->pCache = pCache; - pPage->pgno = pgno; if( pgno==1 ){ pCache->pPage1 = pPage; } diff --git a/src/pcache1.c b/src/pcache1.c index 1a8d6aad29..a80d3375a8 100644 --- a/src/pcache1.c +++ b/src/pcache1.c @@ -16,7 +16,7 @@ ** If the default page cache implementation is overriden, then neither of ** these two features are available. ** -** @(#) $Id: pcache1.c,v 1.7 2009/01/07 15:18:21 danielk1977 Exp $ +** @(#) $Id: pcache1.c,v 1.8 2009/01/23 16:45:01 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -201,7 +201,6 @@ static PgHdr1 *pcache1AllocPage(PCache1 *pCache){ int nByte = sizeof(PgHdr1) + pCache->szPage; PgHdr1 *p = (PgHdr1 *)pcache1Alloc(nByte); if( p ){ - memset(p, 0, nByte); if( pCache->bPurgeable ){ pcache1.nCurrentPage++; } @@ -550,11 +549,13 @@ static void *pcache1Fetch(sqlite3_pcache *p, unsigned int iKey, int createFlag){ if( pPage ){ unsigned int h = iKey % pCache->nHash; - memset(pPage, 0, pCache->szPage + sizeof(PgHdr1)); + *(void **)(PGHDR1_TO_PAGE(pPage)) = 0; pCache->nPage++; pPage->iKey = iKey; pPage->pNext = pCache->apHash[h]; pPage->pCache = pCache; + pPage->pLruPrev = 0; + pPage->pLruNext = 0; pCache->apHash[h] = pPage; } diff --git a/src/sqlite.h.in b/src/sqlite.h.in index e0a9eb132b..950b09f8de 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -30,7 +30,7 @@ ** the version number) and changes its name to "sqlite3.h" as ** part of the build process. ** -** @(#) $Id: sqlite.h.in,v 1.421 2008/12/30 06:24:58 danielk1977 Exp $ +** @(#) $Id: sqlite.h.in,v 1.422 2009/01/23 16:45:01 danielk1977 Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ @@ -6661,17 +6661,17 @@ typedef struct sqlite3_pcache sqlite3_pcache; ** in which case SQLite will attempt to unpin one or more ** pages before re-requesting the same page, or it can ** allocate a new page and return a pointer to it. If a new -** page is allocated, then it must be completely zeroed before -** it is returned. +** page is allocated, then the first sizeof(void*) bytes of +** it (at least) must be zeroed before it is returned. ** 2If createFlag is set to 2, then SQLite is not holding any ** pinned pages associated with the specific cache passed ** as the first argument to xFetch() that can be unpinned. The ** cache implementation should attempt to allocate a new -** cache entry and return a pointer to it. Again, the new -** page should be zeroed before it is returned. If the xFetch() -** method returns NULL when createFlag==2, SQLite assumes that -** a memory allocation failed and returns SQLITE_NOMEM to the -** user. +** cache entry and return a pointer to it. Again, the first +** sizeof(void*) bytes of the page should be zeroed before +** it is returned. If the xFetch() method returns NULL when +** createFlag==2, SQLite assumes that a memory allocation +** failed and returns SQLITE_NOMEM to the user. ** ** ** xUnpin() is called by SQLite with a pointer to a currently pinned page -- 2.47.2