Skip to content

db/state, txpool: benchmark fixes and bench flag improvements#19971

Merged
AskAlexSharov merged 4 commits intomainfrom
anacrolix/bench-fixes
Mar 20, 2026
Merged

db/state, txpool: benchmark fixes and bench flag improvements#19971
AskAlexSharov merged 4 commits intomainfrom
anacrolix/bench-fixes

Conversation

@anacrolix
Copy link
Copy Markdown
Contributor

@anacrolix anacrolix commented Mar 18, 2026

Two independent benchmark fixes.

BenchmarkProcessRemoteTxns panic: mixed b.Loop() (Go 1.24+ API) for the benchmark loop with b.N-based pre-allocation for test data. On the first runN call b.N=1, so only 1 transaction is pre-created, then b.Loop() tries a second iteration and panics with slice bounds out of range [:2] with capacity 1. Fixed by switching back to for i := 0; i < b.N; i++.

bench.loopv split: the shared flag was used in two benchmarks with semantically different meanings — CPU loop iterations in one, milliseconds of sleep in the other. These don't line up in magnitude: a value that makes sense for one (e.g. 100000 CPU iterations ≈ fast) is catastrophic for the other (100000 ms = 100 seconds sleep per iteration). With the default of 100000, BenchmarkDb_BeginFiles_Throughput slept 100 seconds per iteration, completing only 1 iteration in a 112-second run. Split into bench.cpu-iters (default 1000) and bench.sleep-ms (default 5ms, matching the hardcoded value in BenchmarkDb_BeginFiles_Throughput_IO).

…location

b.Loop() manages iteration internally but b.N reflects the pre-allocated
slice size. Using b.Loop() with b.N-based pre-allocation causes a panic
when b.Loop() runs more iterations than b.N. Switch to the standard
i < b.N loop so iteration count matches pre-allocation.
@anacrolix anacrolix marked this pull request as ready for review March 18, 2026 05:17
Copy link
Copy Markdown
Member

@yperbasis yperbasis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One stale reference

Line 552 in BenchmarkDb_BeginFiles_Throughput_IO still has:
//b.Logf("Running with parallel=%d work=%d, #goroutines:%d", *parallel, *loopv, ...)
The PR updates the identical commented-out line in the other two benchmarks but misses this one. Not a build break (it's a comment), just inconsistent. Should be *sleepMs to match.

@AskAlexSharov AskAlexSharov enabled auto-merge (squash) March 19, 2026 01:20
@AskAlexSharov AskAlexSharov added this pull request to the merge queue Mar 20, 2026
Merged via the queue into main with commit edc3722 Mar 20, 2026
33 of 34 checks passed
@AskAlexSharov AskAlexSharov deleted the anacrolix/bench-fixes branch March 20, 2026 04:07
anacrolix added a commit that referenced this pull request Mar 22, 2026
Two independent benchmark fixes.

**`BenchmarkProcessRemoteTxns` panic**: mixed `b.Loop()` (Go 1.24+ API)
for the benchmark loop with `b.N`-based pre-allocation for test data. On
the first `runN` call `b.N=1`, so only 1 transaction is pre-created,
then `b.Loop()` tries a second iteration and panics with `slice bounds
out of range [:2] with capacity 1`. Fixed by switching back to `for i :=
0; i < b.N; i++`.

**`bench.loopv` split**: the shared flag was used in two benchmarks with
semantically different meanings — CPU loop iterations in one,
milliseconds of sleep in the other. These don't line up in magnitude: a
value that makes sense for one (e.g. `100000` CPU iterations ≈ fast) is
catastrophic for the other (`100000 ms = 100 seconds` sleep per
iteration). With the default of `100000`,
`BenchmarkDb_BeginFiles_Throughput` slept 100 seconds per iteration,
completing only 1 iteration in a 112-second run. Split into
`bench.cpu-iters` (default 1000) and `bench.sleep-ms` (default 5ms,
matching the hardcoded value in `BenchmarkDb_BeginFiles_Throughput_IO`).

---------

Co-authored-by: Alex Sharov <AskAlexSharov@gmail.com>
AskAlexSharov added a commit that referenced this pull request Mar 23, 2026
…20070)

Backport of #19971 to release/3.4.

Includes benchmark fixes and bench flag improvements for `db/state` and
`txpool`.

Co-authored-by: Alex Sharov <AskAlexSharov@gmail.com>
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.

3 participants