Performance optimization in sqlite3VdbeAddOp4Int().

FossilOrigin-Name: 456a24324bd42e1e3384ffa8474b7d0760b27df95be0e92ddce5eb87339f6272
This commit is contained in:
drh 2023-06-20 11:46:32 +00:00
parent f82c8cb0d5
commit bcc76bd419
3 changed files with 99 additions and 45 deletions

View File

@ -1,5 +1,5 @@
C Avoid\sunnecessary\sNULL\spointer\schecks\son\scalls\sto\ssqlite3WalkExpr(). C Performance\soptimization\sin\ssqlite3VdbeAddOp4Int().
D 2023-06-19T23:27:22.681 D 2023-06-20T11:46:32.054
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -710,7 +710,7 @@ F src/vdbe.c 6c0de640ef3be08cf2992d588a7501aee0f1003027bc952a6916a35f6e33b4cf
F src/vdbe.h 41485521f68e9437fdb7ec4a90f9d86ab294e9bb8281e33b235915e29122cfc0 F src/vdbe.h 41485521f68e9437fdb7ec4a90f9d86ab294e9bb8281e33b235915e29122cfc0
F src/vdbeInt.h 7bd49eef8f89c1a271fbf12d80a206bf56c876814c5fc6bee340f4e1907095ae F src/vdbeInt.h 7bd49eef8f89c1a271fbf12d80a206bf56c876814c5fc6bee340f4e1907095ae
F src/vdbeapi.c de9703f8705afc393cc2864669ce28cf9516983c8331d59aa2b978de01634365 F src/vdbeapi.c de9703f8705afc393cc2864669ce28cf9516983c8331d59aa2b978de01634365
F src/vdbeaux.c 85627cd1d2fb6e069567128001b55824a170efbc30c2fb1b85261ac30d001b38 F src/vdbeaux.c 4d5e68a3850d0b193a692eca6442d7afe35252aaf29728a67adcb542ecabd9ce
F src/vdbeblob.c 2516697b3ee8154eb8915f29466fb5d4f1ae39ee8b755ea909cefaf57ec5e2ce F src/vdbeblob.c 2516697b3ee8154eb8915f29466fb5d4f1ae39ee8b755ea909cefaf57ec5e2ce
F src/vdbemem.c 710119a8e35e47813681c48703d65a80ba22792192de90bc51dc0d6366f2a79e F src/vdbemem.c 710119a8e35e47813681c48703d65a80ba22792192de90bc51dc0d6366f2a79e
F src/vdbesort.c 0d40dca073c94e158ead752ef4225f4fee22dee84145e8c00ca2309afb489015 F src/vdbesort.c 0d40dca073c94e158ead752ef4225f4fee22dee84145e8c00ca2309afb489015
@ -2040,8 +2040,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 6b3d25b7982623ab4b25161aff9ab44778e136069043ab425543597c42c98ae5 P 73d86a12fb068456a884c030fddd87020d6ec9d56376de541cf082b2104174d3
R 13a078be5369fb5c24d6e73a016aeb7f R e345b05058b93b72d8898bf3dab13eb9
U drh U drh
Z 1aa9d3621a4b2b26b188c794eda5ac16 Z 7f6eefa040de5107043d546e2fa46ab7
# Remove this line to create a well-formed Fossil manifest. # Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
73d86a12fb068456a884c030fddd87020d6ec9d56376de541cf082b2104174d3 456a24324bd42e1e3384ffa8474b7d0760b27df95be0e92ddce5eb87339f6272

View File

@ -218,6 +218,35 @@ static void test_addop_breakpoint(int pc, Op *pOp){
} }
#endif #endif
/*
** Slow paths for sqlite3VdbeAddOp3() and sqlite3VdbeAddOp4Int() for the
** unusual case when we need to increase the size of the Vdbe.aOp[] array
** before adding the new opcode.
*/
static SQLITE_NOINLINE int growOp3(Vdbe *p, int op, int p1, int p2, int p3){
assert( p->nOpAlloc<=p->nOp );
if( growOpArray(p, 1) ) return 1;
assert( p->nOpAlloc>p->nOp );
return sqlite3VdbeAddOp3(p, op, p1, p2, p3);
}
static SQLITE_NOINLINE int addOp4IntSlow(
Vdbe *p, /* Add the opcode to this VM */
int op, /* The new opcode */
int p1, /* The P1 operand */
int p2, /* The P2 operand */
int p3, /* The P3 operand */
int p4 /* The P4 operand as an integer */
){
int addr = sqlite3VdbeAddOp3(p, op, p1, p2, p3);
if( p->db->mallocFailed==0 ){
VdbeOp *pOp = &p->aOp[addr];
pOp->p4type = P4_INT32;
pOp->p4.i = p4;
}
return addr;
}
/* /*
** Add a new instruction to the list of instructions current in the ** Add a new instruction to the list of instructions current in the
** VDBE. Return the address of the new instruction. ** VDBE. Return the address of the new instruction.
@ -228,17 +257,16 @@ static void test_addop_breakpoint(int pc, Op *pOp){
** **
** op The opcode for this instruction ** op The opcode for this instruction
** **
** p1, p2, p3 Operands ** p1, p2, p3, p4 Operands
**
** Use the sqlite3VdbeResolveLabel() function to fix an address and
** the sqlite3VdbeChangeP4() function to change the value of the P4
** operand.
*/ */
static SQLITE_NOINLINE int growOp3(Vdbe *p, int op, int p1, int p2, int p3){ int sqlite3VdbeAddOp0(Vdbe *p, int op){
assert( p->nOpAlloc<=p->nOp ); return sqlite3VdbeAddOp3(p, op, 0, 0, 0);
if( growOpArray(p, 1) ) return 1; }
assert( p->nOpAlloc>p->nOp ); int sqlite3VdbeAddOp1(Vdbe *p, int op, int p1){
return sqlite3VdbeAddOp3(p, op, p1, p2, p3); return sqlite3VdbeAddOp3(p, op, p1, 0, 0);
}
int sqlite3VdbeAddOp2(Vdbe *p, int op, int p1, int p2){
return sqlite3VdbeAddOp3(p, op, p1, p2, 0);
} }
int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){ int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){
int i; int i;
@ -261,6 +289,9 @@ int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){
pOp->p3 = p3; pOp->p3 = p3;
pOp->p4.p = 0; pOp->p4.p = 0;
pOp->p4type = P4_NOTUSED; pOp->p4type = P4_NOTUSED;
/* Replicate this logic in sqlite3VdbeAddOp4Int()
** vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
pOp->zComment = 0; pOp->zComment = 0;
#endif #endif
@ -277,16 +308,59 @@ int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){
#ifdef SQLITE_VDBE_COVERAGE #ifdef SQLITE_VDBE_COVERAGE
pOp->iSrcLine = 0; pOp->iSrcLine = 0;
#endif #endif
/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
** Replicate in sqlite3VdbeAddOp4Int() */
return i; return i;
} }
int sqlite3VdbeAddOp0(Vdbe *p, int op){ int sqlite3VdbeAddOp4Int(
return sqlite3VdbeAddOp3(p, op, 0, 0, 0); Vdbe *p, /* Add the opcode to this VM */
} int op, /* The new opcode */
int sqlite3VdbeAddOp1(Vdbe *p, int op, int p1){ int p1, /* The P1 operand */
return sqlite3VdbeAddOp3(p, op, p1, 0, 0); int p2, /* The P2 operand */
} int p3, /* The P3 operand */
int sqlite3VdbeAddOp2(Vdbe *p, int op, int p1, int p2){ int p4 /* The P4 operand as an integer */
return sqlite3VdbeAddOp3(p, op, p1, p2, 0); ){
int i;
VdbeOp *pOp;
i = p->nOp;
if( p->nOpAlloc<=i ){
return addOp4IntSlow(p, op, p1, p2, p3, p4);
}
p->nOp++;
pOp = &p->aOp[i];
assert( pOp!=0 );
pOp->opcode = (u8)op;
pOp->p5 = 0;
pOp->p1 = p1;
pOp->p2 = p2;
pOp->p3 = p3;
pOp->p4.i = p4;
pOp->p4type = P4_INT32;
/* Replicate this logic in sqlite3VdbeAddOp3()
** vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
pOp->zComment = 0;
#endif
#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
pOp->nExec = 0;
pOp->nCycle = 0;
#endif
#ifdef SQLITE_DEBUG
if( p->db->flags & SQLITE_VdbeAddopTrace ){
sqlite3VdbePrintOp(0, i, &p->aOp[i]);
test_addop_breakpoint(i, &p->aOp[i]);
}
#endif
#ifdef SQLITE_VDBE_COVERAGE
pOp->iSrcLine = 0;
#endif
/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
** Replicate in sqlite3VdbeAddOp3() */
return i;
} }
/* Generate code for an unconditional jump to instruction iDest /* Generate code for an unconditional jump to instruction iDest
@ -494,26 +568,6 @@ void sqlite3VdbeAddParseSchemaOp(Vdbe *p, int iDb, char *zWhere, u16 p5){
sqlite3MayAbort(p->pParse); sqlite3MayAbort(p->pParse);
} }
/*
** Add an opcode that includes the p4 value as an integer.
*/
int sqlite3VdbeAddOp4Int(
Vdbe *p, /* Add the opcode to this VM */
int op, /* The new opcode */
int p1, /* The P1 operand */
int p2, /* The P2 operand */
int p3, /* The P3 operand */
int p4 /* The P4 operand as an integer */
){
int addr = sqlite3VdbeAddOp3(p, op, p1, p2, p3);
if( p->db->mallocFailed==0 ){
VdbeOp *pOp = &p->aOp[addr];
pOp->p4type = P4_INT32;
pOp->p4.i = p4;
}
return addr;
}
/* Insert the end of a co-routine /* Insert the end of a co-routine
*/ */
void sqlite3VdbeEndCoroutine(Vdbe *v, int regYield){ void sqlite3VdbeEndCoroutine(Vdbe *v, int regYield){