go-sqlite3 icon indicating copy to clipboard operation
go-sqlite3 copied to clipboard

reduce allocations when binding string/time args

Open charlievieth opened this issue 1 year ago • 3 comments

This commit reduces the number of allocations required to bind args by eliminating string to byte slice conversions for string and time.Time types and by only checking for bind parameters if any of the driver.NamedValue args are named. It also changes bind to only reset the sqlite3 statement when necessary - previously the statement was always reset even on first use (this yields a 3-4% performance boost).

goos: darwin
goarch: arm64
pkg: github.com/mattn/go-sqlite3
cpu: Apple M4 Pro
                         │   y1.txt    │               y2.txt               │
                         │   sec/op    │   sec/op     vs base               │
Suite/BenchmarkQuery-14    2.080µ ± 3%   1.995µ ± 0%  -4.13% (p=0.000 n=10)
Suite/BenchmarkParams-14   2.282µ ± 1%   2.181µ ± 2%  -4.43% (p=0.000 n=10)
Suite/BenchmarkStmt-14     1.537µ ± 1%   1.489µ ± 1%  -3.16% (p=0.000 n=10)
geomean                    1.939µ        1.864µ       -3.91%

                         │   y1.txt    │                y2.txt                 │
                         │    B/op     │    B/op      vs base                  │
Suite/BenchmarkQuery-14     688.0 ± 0%    688.0 ± 0%        ~ (p=1.000 n=10) ¹
Suite/BenchmarkParams-14   1104.0 ± 0%   1000.0 ± 0%   -9.42% (p=0.000 n=10)
Suite/BenchmarkStmt-14      920.0 ± 0%    816.0 ± 0%  -11.30% (p=0.000 n=10)
geomean                     887.4         824.9        -7.04%
¹ all samples are equal

                         │   y1.txt   │               y2.txt                │
                         │ allocs/op  │ allocs/op   vs base                 │
Suite/BenchmarkQuery-14    23.00 ± 0%   23.00 ± 0%       ~ (p=1.000 n=10) ¹
Suite/BenchmarkParams-14   27.00 ± 0%   25.00 ± 0%  -7.41% (p=0.000 n=10)
Suite/BenchmarkStmt-14     25.00 ± 0%   23.00 ± 0%  -8.00% (p=0.000 n=10)
geomean                    24.95        23.65       -5.20%
¹ all samples are equal

charlievieth avatar Nov 05 '24 17:11 charlievieth

~Note: this PR includes https://github.com/mattn/go-sqlite3/pull/1294 since it fixes the CIFuzz and macOS tests.~

This is no longer true since that commit/pr are no longer needed to make the CI tests pass.

charlievieth avatar Nov 05 '24 18:11 charlievieth

@mattn / @rittneje I know this time of year is pretty busy, but was wondering if either of you had the time to take a look at this PR?

charlievieth avatar Dec 18 '24 00:12 charlievieth

Which is your latest PR?

mattn avatar Apr 01 '25 14:04 mattn