Skip to content

perf(generate): refresh gas weights a window of entries at a time - #367

Merged
onbjerg merged 1 commit into
mainfrom
onbjerg/gas-refresh-windows
Nov 27, 2026
Merged

onbjerg merged 1 commit into
mainfrom
onbjerg/gas-refresh-windows

Conversation

@onbjerg

@onbjerg onbjerg commented Nov 27, 2026

Copy link
Copy Markdown
Member

generate --gas-weighted-mix built a gas probe for every mix entry on the generation loop each refresh (#357). Each probe copies the nonce tracker, so with neobank-multi's per-user vault and zone templates (~40k entries, ~40k tracked accounts) every refresh paused generation for 0.6–1.2 s. bench send has nothing to send while generate is paused and never catches up, so capacity runs came in 5–9% under target.

A refresh pass now samples the mix 64 entries at a time and starts the next window as soon as the previous one returns. A pass still covers every entry, passes still start every 10 s, and the first sample still covers the whole mix before any workload is emitted. Each window's estimates apply by entry id. Mixes of up to 64 entries refresh exactly as before.

With 40k entries and a 40k-account nonce tracker (release build), building every probe took 2.3 s; one window takes 4 ms.

Checks: nightly fmt, clippy -D warnings, cargo test -p txgen-cli (186 passed, 3 new). Rerunning the affected capacity benches on this rev before merging.

A gas refresh built a probe for every mix entry on the generation loop
before handing the simulations to the runtime (#357). Each probe copies
the nonce tracker, so with neobank-multi's per-user vault and zone
templates (about 40,000 entries and 40,000 tracked accounts) every
refresh paused generation for 0.6-1.2 s on the bench hosts. bench send
has nothing to send while generate is paused and never catches up, so
capacity runs fell 5-9% short of their target and were read as
under-driven.

A refresh pass now samples the mix 64 entries at a time and starts the
next window as soon as the previous one returns, so a pass still covers
every entry and passes still start every 10 s. Each window's estimates
apply by entry id when it returns, and the first sample still covers
the whole mix before any workload is emitted. A mix of up to 64 entries
refreshes exactly as before.

With 40,000 entries and a 40,000-account nonce tracker (release build),
building every probe took 2.3 s and one window takes 4 ms.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM. The windowed gas refresh is correct as far as I can tell, and the first sample still covers the whole mix before anything is emitted.

What was reviewed:

  • gas_refresh_window cursor handling: a pass always ends on cursor 0, a returned next cursor is never 0 in the middle of a pass, and if pruning drops every entry past the cursor the result is an empty window that just closes the pass.
  • set_sampled_gas_estimates id matching against pick's order-preserving retain: samples for pruned entries are skipped, unsampled entries keep their weights, totals are recomputed, and zero gas is still rejected.
  • Loop timing: last_gas_sample now resets only when a pass starts, and a failed window logs and moves on, the same as a failed refresh did before.
Extended reasoning...

The change touches only crates/txgen-cli/src/generate.rs. It splits the periodic gas-weight refresh of generate --gas-weighted-mix into windows of 64 entries matched by mix-entry id, and adds three tests covering window coverage, partial updates and an end-to-end mocked RPC run. It touches no security-sensitive surface such as auth, crypto or untrusted input handling; it is a performance change in a load-generation tool. The state machine is small, and reading the cursor, pruning and estimate-application edge cases showed no defects. The repository has no CODEOWNERS file, and the PR has no outstanding reviewer objections.

@onbjerg
onbjerg merged commit f3b60dd into main Nov 27, 2026
11 checks passed
@onbjerg
onbjerg deleted the onbjerg/gas-refresh-windows branch November 27, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant