Repository navigation
perf(generate): refresh gas weights a window of entries at a time - #367
Conversation
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.
There was a problem hiding this comment.
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_windowcursor 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_estimatesid matching againstpick's order-preservingretain: samples for pruned entries are skipped, unsampled entries keep their weights, totals are recomputed, and zero gas is still rejected.- Loop timing:
last_gas_samplenow 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.
generate --gas-weighted-mixbuilt 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 sendhas nothing to send whilegenerateis 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.