Skip to content

Add prepared plans option to bench database tests#1815

Merged
fbac merged 1 commit intomainfrom
fbac/prepared-queries
Mar 16, 2026
Merged

Add prepared plans option to bench database tests#1815
fbac merged 1 commit intomainfrom
fbac/prepared-queries

Conversation

@fbac
Copy link
Copy Markdown
Collaborator

@fbac fbac commented Mar 12, 2026

TLDR

Total benchmarks: 25
Consistent gains: 13
Consistent regressions: 3
Mixed/noisy: 9

Consistent gains

BenchmarkSelectGatewayEnvelopesByTopics/rows=1M-14 (avg ~-30.8%)
BenchmarkSelectGatewayEnvelopesBySingleOriginator/rows=1M-14 (avg ~-23.6%)
BenchmarkInsertGatewayEnvelopeBatch/rows=1M-14 (avg ~-20.8%)
BenchmarkGetLastEvent-14 (avg ~-14.9%)
BenchmarkIncrementUnsettledUsage-14 (avg ~-12.6%)
BenchmarkHotPathFullCycle-14 (avg ~-12.5%)
BenchmarkHotPathSelectStaged-14 (avg ~-11.9%)
BenchmarkHotPathInsertStaged-14 (avg ~-9.5%)
BenchmarkHotPathDeleteStaged-14 (avg ~-8.0%)
BenchmarkSelectGatewayEnvelopesUnfiltered/rows=1M-14 (avg ~-7.7%)
BenchmarkSelectNewestFromTopics/rows=1M-14 (avg ~-7.4%)
BenchmarkSelectGatewayEnvelopesByOriginators/rows=1M-14 (avg ~-7.4%)
BenchmarkGetRecentOriginatorCongestion-14 (avg ~-6.9%)

Consistent regressions

BenchmarkHotPathBatchCycle/batch=100-14 (avg ~+26.2%)
BenchmarkHotPathBatchCycle/batch=1-14 (avg ~+9.9%)
BenchmarkInsertPayerLedgerEvent-14 (avg ~+44.0%, but driven by a large outlier in POST4)

Mixed/noisy

BenchmarkSetLatestBlock-14
BenchmarkSumOriginatorCongestion-14
BenchmarkGetPayerBalance-14
BenchmarkIncrementOriginatorCongestion-14
BenchmarkInsertGatewayEnvelope/rows=1M-14
BenchmarkHotPathBatchCycle/batch=10-14
BenchmarkHotPathInsertGatewayWithUsage-14
BenchmarkHotPathBatchCycle/batch=500-14
BenchmarkGetLatestBlock-14

Note

Add prepared query support to database benchmarks via BENCH_USE_PREPARED flag

  • Enables sqlc prepared query emission (emit_prepared_queries: true) and generates Prepare, Close, and routing helpers (exec, query, queryRow) in pkg/db/queries/db.go.
  • Adds BENCH_USE_PREPARED env var (default true) to dev/bench and pkg/db/bench/main_test.go to toggle prepared statements at benchmark runtime.
  • Refactors all bench test files to use shared, package-level *queries.Queries instances (e.g. congestionQueries, hotPathQueries) instead of constructing local query objects per benchmark.
  • Behavioral Change: benchmarks now default to prepared statements; set BENCH_USE_PREPARED=false to revert to unprepared queries.

Macroscope summarized 4c40719.

@fbac fbac requested a review from a team as a code owner March 12, 2026 19:34
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented Mar 12, 2026

Approvability

Verdict: Approved

Test infrastructure change that adds prepared query support to database benchmarks. All changes are in benchmark test files and auto-generated sqlc code, with no impact on production runtime. The author owns all modified files.

You can customize Macroscope's approvability policy. Learn more.

@fbac fbac merged commit 3d47fc0 into main Mar 16, 2026
16 of 17 checks passed
@fbac fbac deleted the fbac/prepared-queries branch March 16, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants