]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Performance improvements to the (debug-use only) Mem.pScopyFrom logic, resulting
authordrh <>
Tue, 21 Jan 2025 16:30:55 +0000 (16:30 +0000)
committerdrh <>
Tue, 21 Jan 2025 16:30:55 +0000 (16:30 +0000)
in about 8x faster performance under -DSQLITE_DEBUG for the query in from
[forum:/forumpost/0025389d0860af82|forum post 0025389d0860af82].  This change
only affects builds that use -DSQLITE_DEBUG.

FossilOrigin-Name: 7fb1ae25d1572dd7709a0f850c148a5f745a524f01ea231e29a1ebc37c173fb9

manifest
manifest.uuid
src/vdbe.c
src/vdbeInt.h
src/vdbeapi.c
src/vdbeaux.c
src/vdbemem.c

index b6f6b78089613944d1a6f349837246c5fa1624d3..b9e1cd0b1e5143351940b0ea52ff864d7f54090e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C The\sFuncDev.nArg\sfield\svalues\s-3\sand\s-4\snow\shave\sspecial\smeansing\sof\s1\sor\smore\nor\s2\sor\smore\sarguments,\srespectively.\s\sThis\ssaves\sspace\sin\sthe\sbuilt-in\nfunction\stable,\sresulting\sin\sslightly\sfaster\sperformance\sand\sa\sreduced\sbinary\nsize.
-D 2025-01-21T15:12:00.408
+C Performance\simprovements\sto\sthe\s(debug-use\sonly)\sMem.pScopyFrom\slogic,\sresulting\nin\sabout\s8x\sfaster\sperformance\sunder\s-DSQLITE_DEBUG\sfor\sthe\squery\sin\sfrom\n[forum:/forumpost/0025389d0860af82|forum\spost\s0025389d0860af82].\s\sThis\schange\nonly\saffects\sbuilds\sthat\suse\s-DSQLITE_DEBUG.
+D 2025-01-21T16:30:55.694
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md e108e1e69ae8e8a59e93c455654b8ac9356a11720d3345df2a4743e9590fb20d
@@ -848,13 +848,13 @@ F src/upsert.c 215328c3f91623c520ec8672c44323553f12caeb4f01b1090ebdca99fdf7b4f1
 F src/utf.c 8b29d9a5956569ea2700f869669b8ef67a9662ee5e724ff77ab3c387e27094ba
 F src/util.c e5f6a5eeaa26b69054a43bbd0048cfe3d2851f6961052b35aed8f695df922850
 F src/vacuum.c b763b6457bd058d2072ef9364832351fd8d11e8abf70cbb349657360f7d55c40
-F src/vdbe.c 8a6eb02823b424b273614bae41579392a5c495424592b60423dd2c443a583df0
+F src/vdbe.c b428a751953c0c2ff85e3e152ec16e29d488895cd541c8c20876ff9f3bf6978a
 F src/vdbe.h 9676348d342bd04e21e384c63b57224171ce84fac77853357334ef94c4d33cf4
-F src/vdbeInt.h bf294a0c8fc4cc80779e74b04b8bd82c6e1197b3137cefe0b16cdf002fc7dfd6
-F src/vdbeapi.c 033decc098df353b97a5ca14302ad812e2567f1037747c2d5fcda62aac1bb74e
-F src/vdbeaux.c 5fcbc642a3d3d88c5ea15cadf2c8b8e4e067cb9ff374beb1875c9d209001299e
+F src/vdbeInt.h 895b1ab7536f018d3d70d690f6c0adbd1062b6dddce1c2cad912927856d4033c
+F src/vdbeapi.c 76fa76b21f46afc70e71ecd69954f601e9b80b5fb0c1eb7ace06d30802255768
+F src/vdbeaux.c 885e16100597507fbbe09d82cbb963bff3fd8a9c1e358dc4f463fc95feb18e8b
 F src/vdbeblob.c 255be187436da38b01f276c02e6a08103489bbe2a7c6c21537b7aecbe0e1f797
-F src/vdbemem.c df568ef0187e4be2788c35174f6d9b8566ab9475f9aff2d73907ed05aa5684b2
+F src/vdbemem.c 977438546df236c6a3e7d8b4fe86c0643c13b89b00235db1f11c3a91a4796d30
 F src/vdbesort.c d0a3c7056c081703c8b6d91ad60f17da5e062a5c64bf568ed0fa1b5f4cae311f
 F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823
 F src/vdbevtab.c fc46b9cbd759dc013f0b3724549cc0d71379183c667df3a5988f7e2f1bd485f3
@@ -2208,8 +2208,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350
 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
 F tool/warnings.sh 49a486c5069de041aedcbde4de178293e0463ae9918ecad7539eedf0ec77a139
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P f418350f3f83147bc5817a885be6e39ff9ff5722742a88d17600729c53c65010
-R 214f345108f048affd4b7abd9f2ea035
+P 753fd747f24c5e9a019eb00b8a4f66e65c6733ba10a7adbd1b55786867c32ca6
+R f2e8145ad0d67966271c1c923a7301c7
 U drh
-Z b46d6184b5d599a41424bec3e41b4c80
+Z 86ef734f24e1aa297cb586202f4cb17a
 # Remove this line to create a well-formed Fossil manifest.
index bad8235170d928d88dd3ee5d6a42a1ffe92a74c9..14622345fc645836d0d56994969a0a4177163e83 100644 (file)
@@ -1 +1 @@
-753fd747f24c5e9a019eb00b8a4f66e65c6733ba10a7adbd1b55786867c32ca6
+7fb1ae25d1572dd7709a0f850c148a5f745a524f01ea231e29a1ebc37c173fb9
index 558970ed953c06cc65045048213dab370faffdf9..d41ac8d51744b44ae88ee58070d4e26353232b9a 100644 (file)
@@ -607,6 +607,7 @@ static void registerTrace(int iReg, Mem *p){
   printf("R[%d] = ", iReg);
   memTracePrint(p);
   if( p->pScopyFrom ){
+    assert( p->pScopyFrom->bScopy );
     printf(" <== R[%d]", (int)(p->pScopyFrom - &p[-iReg]));
   }
   printf("\n");
@@ -1590,6 +1591,7 @@ case OP_Move: {
     { int i;
       for(i=1; i<p->nMem; i++){
         if( aMem[i].pScopyFrom==pIn1 ){
+          assert( aMem[i].bScopy );
           aMem[i].pScopyFrom = pOut;
         }
       }
@@ -1662,6 +1664,7 @@ case OP_SCopy: {            /* out2 */
 #ifdef SQLITE_DEBUG
   pOut->pScopyFrom = pIn1;
   pOut->mScopyFlags = pIn1->flags;
+  pIn1->bScopy = 1;
 #endif
   break;
 }
index 2cb4f8c2a1b1ca3926862d755e8d4661f6f8e1dc..24cf1ac56c864e6c5434b65d9f7b788fa118a194 100644 (file)
@@ -244,6 +244,7 @@ struct sqlite3_value {
 #ifdef SQLITE_DEBUG
   Mem *pScopyFrom;    /* This Mem is a shallow copy of pScopyFrom */
   u16 mScopyFlags;    /* flags value immediately after the shallow copy */
+  u8  bScopy;         /* The pScopyFrom of some other Mem *might* point here */
 #endif
 };
 
index 5fc04b139c2776f484acc6d5432e9b04cb02f697..113b8a9c04d09f99da80e1a1b0ab018e9ef4a326 100644 (file)
@@ -1294,6 +1294,7 @@ static const Mem *columnNullValue(void){
 #ifdef SQLITE_DEBUG
         /* .pScopyFrom = */ (Mem*)0,
         /* .mScopyFlags= */ 0,
+        /* .bScopy     = */ 0,
 #endif
       };
   return &nullMem;
index b9e8b3cdf8f17965f741425e8a6642ec12fc7cc9..81dca10f02b08087714def5e3ec28bd466975d5a 100644 (file)
@@ -2152,6 +2152,7 @@ static void initMemArray(Mem *p, int N, sqlite3 *db, u16 flags){
       p->szMalloc = 0;
 #ifdef SQLITE_DEBUG
       p->pScopyFrom = 0;
+      p->bScopy = 0;
 #endif
       p++;
     }while( (--N)>0 );
index 0fc6b68f5e774a2dfafb5727e486d5715c949aa3..38ba5abe80eb286e5bebf3c724722cfd73c3d5a4 100644 (file)
@@ -1046,27 +1046,30 @@ int sqlite3VdbeMemTooBig(Mem *p){
 void sqlite3VdbeMemAboutToChange(Vdbe *pVdbe, Mem *pMem){
   int i;
   Mem *pX;
-  for(i=1, pX=pVdbe->aMem+1; i<pVdbe->nMem; i++, pX++){
-    if( pX->pScopyFrom==pMem ){
-      u16 mFlags;
-      if( pVdbe->db->flags & SQLITE_VdbeTrace ){
-        sqlite3DebugPrintf("Invalidate R[%d] due to change in R[%d]\n",
-          (int)(pX - pVdbe->aMem), (int)(pMem - pVdbe->aMem));
+  if( pMem->bScopy ){
+    for(i=1, pX=pVdbe->aMem+1; i<pVdbe->nMem; i++, pX++){
+      if( pX->pScopyFrom==pMem ){
+        u16 mFlags;
+        if( pVdbe->db->flags & SQLITE_VdbeTrace ){
+          sqlite3DebugPrintf("Invalidate R[%d] due to change in R[%d]\n",
+            (int)(pX - pVdbe->aMem), (int)(pMem - pVdbe->aMem));
+        }
+        /* If pX is marked as a shallow copy of pMem, then try to verify that
+        ** no significant changes have been made to pX since the OP_SCopy.
+        ** A significant change would indicated a missed call to this
+        ** function for pX.  Minor changes, such as adding or removing a
+        ** dual type, are allowed, as long as the underlying value is the
+        ** same. */
+        mFlags = pMem->flags & pX->flags & pX->mScopyFlags;
+        assert( (mFlags&(MEM_Int|MEM_IntReal))==0 || pMem->u.i==pX->u.i );
+        
+        /* pMem is the register that is changing.  But also mark pX as
+        ** undefined so that we can quickly detect the shallow-copy error */
+        pX->flags = MEM_Undefined;
+        pX->pScopyFrom = 0;
       }
-      /* If pX is marked as a shallow copy of pMem, then try to verify that
-      ** no significant changes have been made to pX since the OP_SCopy.
-      ** A significant change would indicated a missed call to this
-      ** function for pX.  Minor changes, such as adding or removing a
-      ** dual type, are allowed, as long as the underlying value is the
-      ** same. */
-      mFlags = pMem->flags & pX->flags & pX->mScopyFlags;
-      assert( (mFlags&(MEM_Int|MEM_IntReal))==0 || pMem->u.i==pX->u.i );
-      
-      /* pMem is the register that is changing.  But also mark pX as
-      ** undefined so that we can quickly detect the shallow-copy error */
-      pX->flags = MEM_Undefined;
-      pX->pScopyFrom = 0;
     }
+    pMem->bScopy = 0;
   }
   pMem->pScopyFrom = 0;
 }