You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix exponential memory allocation in SQLiteConn.Exec
This commit fixes SQLiteConn.Exec to not duplicate the provided SQL
statement and to pass the Go string to libsqlite3 instead of creating
a C string copy and passing that. The issue with the previous
implementation was that it would create a new C string copy of the
original Go string each time it stepped through a SQL statement. This
led to exponential memory usage when Exec'ing an argument that contained
multiple SQL statements (which is common when initializing a database
from a SQL dump).
This commit is a slimmed down version of PR mattn#1133:
mattn#1133
```
goos: darwin
goarch: arm64
pkg: github.com/mattn/go-sqlite3
cpu: Apple M1 Max
│ b.txt │ n.txt │
│ sec/op │ sec/op vs base │
Suite/BenchmarkExec-10 1.278µ ± 1% 1.022µ ± 2% -19.99% (p=0.000 n=10)
Suite/BenchmarkExecStep-10 1762.9µ ± 0% 900.9µ ± 1% -48.90% (p=0.000 n=10)
geomean 47.47µ 30.35µ -36.06%
│ b.txt │ n.txt │
│ B/op │ B/op vs base │
Suite/BenchmarkExec-10 128.0 ± 0% 120.0 ± 0% -6.25% (p=0.000 n=10)
Suite/BenchmarkExecStep-10 5279.94Ki ± 0% 31.34Ki ± 0% -99.41% (p=0.000 n=10)
geomean 25.69Ki 1.916Ki -92.54%
│ b.txt │ n.txt │
│ allocs/op │ allocs/op vs base │
Suite/BenchmarkExec-10 7.000 ± 0% 6.000 ± 0% -14.29% (p=0.000 n=10)
Suite/BenchmarkExecStep-10 7.000k ± 0% 3.003k ± 0% -57.10% (p=0.000 n=10)
geomean 221.4 134.2 -39.36%
```
0 commit comments