Skip to content

fix: in microbench, hash LRU caches with fixed seed - #2008

Open
jkaczman wants to merge 1 commit into
mainfrom
jk-bench-lru-fixed-seed
Open

jkaczman wants to merge 1 commit into
mainfrom
jk-bench-lru-fixed-seed

Conversation

@jkaczman

Copy link
Copy Markdown
Contributor

Follow up work to try to improve accuracy of microbench instructions in reference to #2003 seeing a +1.54% increase for a measure that shouldn't have been affected by that PR.

After some investigation, this seems to be because our LRU caches hash with foldhash, which builds a hash seed from code addresses (as a source of randomness). My guess is that this can change the order that we free cache entries in, and with that differs the work of all subsequent malloc calls.

Reference to their code that does this: https://github.com/orlp/foldhash/blob/77d8e3dae0d43abe65753e888b9e74efbe4ee3f7/src/seed.rs#L150-L156

Now, in the microbench, the LRU caches hash with a fixed seed (via foldhash::fast::FixedState, which they recommend for determinism).

This doesn't affect production builds.

@codecov

codecov Bot commented Nov 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread pgdog/Cargo.toml
bench = []

[dependencies]
foldhash = { version = "0.2", default-features = false }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You could make it conditional, i.e., only if bench feature is enabled. Although LLVM will probably remove it anyway during compilation / dead code elimination.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Metal bench (arm64) passed. All 517 measures within bounds.

suite throughput cpu/txn user cycles/txn user instr/txn kernel cycles/txn kernel instr/txn ctx/txn
pooler 19.54 (-0.3% ± 1.4%) 19,370 (-0.8% ± 0.6%) 32,042 (+0.0% ± 0.07%) 30,905 (-0.2% ± 2.5%) 50,975 (-0.1% ± 0.3%)
lb 20.12 (-0.2% ± 2.2%) 20,112 (+0.7% ± 1.5%) 32,939 (-0.0% ± 0.05%) 31,382 (-0.9% ± 3.2%) 52,133 (-0.0% ± 0.4%)
sharding-w2 32.98 (-0.7% ± 1.7%) 44,777 (-0.5% ± 1.2%) 97,448 (+0.0% ± 0.00%) 41,220 (-1.0% ± 4.3%) 53,628 (+0.0% ± 0.2%) 1.54 (+0.1% ± 0.2%)
sharding-w8 243,019 (+2.1% ± 3.2%) 29.48 (-2.3% ± 2.9%) 44,674 (-1.6% ± 1.4%) 52,985 (-0.0% ± 0.1%) 36,790 (-3.3% ± 5.3%) 42,384 (+0.0% ± 0.07%) 0.1675 (+2.6% ± 1.3%)
Counters per txn
suite frontend stall l1i refill backend stall
pooler 9,043 (-2.4% ± 1.6%) 2,814 (-1.3% ± 1.0%)
lb 9,547 (+0.7% ± 3.5%) 2,899 (+0.1% ± 1.6%)
sharding-w2 19,151 (-1.0% ± 3.3%) 4,231 (-0.6% ± 2.7%)
sharding-w8 20,802 (-3.0% ± 2.3%) 4,191 (-1.0% ± 2.5%)

Microbench: all 504 measures within bounds.

Hot code per txn
path base head change
pooler 111.2 KB 110.6 KB -0.6 KB
sharding-w2 166.8 KB 166.8 KB +0.1 KB

pooler:

crate base head change
pgdog::frontend::client::query_engine 19.8 KB 19.8 KB +0.0 KB
tokio 18.4 KB 18.2 KB -0.2 KB
pgdog::backend::pool 17.7 KB 17.4 KB -0.2 KB
aws-lc (TLS crypto) 10.0 KB 9.8 KB -0.2 KB
rustls (TLS) 8.4 KB 8.4 KB +0.1 KB
pgdog::frontend (other) 7.8 KB 7.8 KB +0.0 KB
pgdog::backend::server 7.2 KB 7.3 KB +0.1 KB
other 6.4 KB 6.3 KB -0.1 KB
everything else 15.5 KB 15.5 KB +0.0 KB
function head change
pgdog::frontend::client::Client::run::{{closure}} 5.4 KB -0.1 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 5.4 KB +0.0 KB
pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}} 4.0 KB +0.0 KB
tokio::runtime::task::raw::poll 3.0 KB -0.2 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 2.8 KB +0.0 KB

sharding-w2:

crate base head change
pgdog::frontend::router 29.0 KB 28.8 KB -0.2 KB
pgdog::frontend::client::query_engine 20.9 KB 20.9 KB +0.0 KB
tokio 19.4 KB 19.4 KB +0.0 KB
pgdog::backend::pool 18.5 KB 18.6 KB +0.1 KB
aws-lc (TLS crypto) 12.5 KB 13.0 KB +0.5 KB
other 9.6 KB 9.9 KB +0.4 KB
pgdog::frontend (other) 8.7 KB 8.6 KB -0.1 KB
rustls (TLS) 8.2 KB 8.2 KB +0.0 KB
everything else 40.0 KB 39.5 KB -0.5 KB
function head change
pgdog::frontend::client::Client::run::{{closure}} 6.0 KB -0.1 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 5.1 KB -0.1 KB
pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}} 4.1 KB +0.0 KB
pgdog::frontend::router::parser::query::select::<impl pgdog::frontend::router::parser::que 3.4 KB +0.1 KB
tokio::runtime::task::raw::poll 3.3 KB +0.0 KB
lb flamegraph vs e9316d2

lb

Open interactive for hover, zoom and search.

lb removed

Open interactive.

microbench flamegraph vs e9316d2

microbench

Open interactive for hover, zoom and search.

microbench removed

Open interactive.

pooler flamegraph vs e9316d2

pooler

Open interactive for hover, zoom and search.

pooler removed

Open interactive.

sharding-w2 flamegraph vs e9316d2

sharding-w2

Open interactive for hover, zoom and search.

sharding-w2 removed

Open interactive.

sharding-w8 flamegraph vs e9316d2

sharding-w8

Open interactive for hover, zoom and search.

sharding-w8 removed

Open interactive.

Logs

lb, microbench, pooler, sharding-w2, sharding-w8, verdict.json

Compared a2b6aa9 with e9316d2 on m8g.metal-24xl (spot).

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Metal bench (x86) passed. All 517 measures within bounds.

suite throughput cpu/txn user cycles/txn user instr/txn kernel cycles/txn kernel instr/txn ctx/txn
pooler 34.63 (+0.1% ± 0.2%) 22,808 (+0.5% ± 0.4%) 33,987 (-0.0% ± 0.02%) 57,821 (+0.1% ± 0.4%) 38,540 (-0.1% ± 0.1%)
lb 35.58 (-0.0% ± 0.2%) 23,853 (+0.3% ± 0.4%) 34,935 (-0.0% ± 0.02%) 58,755 (-0.1% ± 0.3%) 39,233 (+0.0% ± 0.1%)
sharding-w2 56.63 (+0.2% ± 0.5%) 53,668 (+0.6% ± 0.7%) 101,372 (-0.0% ± 0.06%) 73,140 (-0.0% ± 0.9%) 43,130 (-0.0% ± 0.4%) 1.392 (-0.2% ± 0.3%)
sharding-w8 148,661 (-0.0% ± 1.5%) 48.35 (+0.4% ± 0.2%) 58,552 (+0.8% ± 1.1%) 56,812 (+0.0% ± 0.07%) 64,317 (+0.1% ± 0.5%) 34,215 (-0.0% ± 0.2%) 0.1673 (+0.0% ± 2.0%)
Counters per txn
suite frontend stall l1i refill backend stall
pooler 72,760 (+1.4% ± 0.6%) 3,606 (+1.5% ± 0.3%)
lb 75,668 (+1.3% ± 1.1%) 3,733 (+1.5% ± 0.2%)
sharding-w2 161,448 (+1.6% ± 1.1%) 6,008 (+1.0% ± 0.7%)
sharding-w8 127,138 (+1.9% ± 0.4%) 4,868 (+0.8% ± 1.3%)

Microbench: all 504 measures within bounds.

Hot code per txn
path base head change
pooler 103.9 KB 105.6 KB +1.7 KB
sharding-w2 158.9 KB 160.4 KB +1.4 KB

pooler:

crate base head change
pgdog::frontend::client::query_engine 19.6 KB 20.1 KB +0.5 KB
tokio 17.4 KB 17.6 KB +0.2 KB
pgdog::backend::pool 17.4 KB 17.4 KB +0.0 KB
pgdog::frontend (other) 8.6 KB 9.0 KB +0.4 KB
rustls (TLS) 6.9 KB 7.8 KB +0.9 KB
aws-lc (TLS crypto) 7.3 KB 7.0 KB -0.3 KB
pgdog::backend::server 6.4 KB 6.6 KB +0.2 KB
other 5.9 KB 5.8 KB -0.1 KB
everything else 14.3 KB 14.2 KB -0.1 KB
function head change
pgdog::frontend::client::Client::run::{{closure}} 6.9 KB +0.3 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 5.9 KB -0.1 KB
pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}} 4.6 KB +0.2 KB
tokio::runtime::task::raw::poll 3.7 KB +0.2 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 3.1 KB -0.1 KB

sharding-w2:

crate base head change
pgdog::frontend::router 27.9 KB 28.4 KB +0.4 KB
pgdog::frontend::client::query_engine 21.6 KB 22.2 KB +0.6 KB
pgdog::backend::pool 17.8 KB 18.7 KB +0.9 KB
tokio 17.8 KB 17.9 KB +0.1 KB
aws-lc (TLS crypto) 10.1 KB 10.4 KB +0.3 KB
other 10.7 KB 10.1 KB -0.6 KB
pgdog::frontend (other) 9.7 KB 10.0 KB +0.3 KB
pgdog::backend::server 7.3 KB 7.4 KB +0.1 KB
everything else 36.0 KB 35.2 KB -0.8 KB
function head change
pgdog::frontend::client::Client::run::{{closure}} 7.4 KB +0.2 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 6.0 KB +0.2 KB
pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}} 4.9 KB +0.2 KB
pgdog::frontend::router::parser::query::select::<impl pgdog::frontend::router::parser::que 4.1 KB +0.2 KB
tokio::runtime::task::raw::poll 3.9 KB +0.1 KB
lb flamegraph vs e9316d2

lb

Open interactive for hover, zoom and search.

lb removed

Open interactive.

microbench flamegraph vs e9316d2

microbench

Open interactive for hover, zoom and search.

microbench removed

Open interactive.

pooler flamegraph vs e9316d2

pooler

Open interactive for hover, zoom and search.

pooler removed

Open interactive.

sharding-w2 flamegraph vs e9316d2

sharding-w2

Open interactive for hover, zoom and search.

sharding-w2 removed

Open interactive.

sharding-w8 flamegraph vs e9316d2

sharding-w8

Open interactive for hover, zoom and search.

sharding-w8 removed

Open interactive.

Logs

lb, microbench, pooler, sharding-w2, sharding-w8, verdict.json

Compared a2b6aa9 with e9316d2 on c7a.metal-48xl (spot).

@jkaczman
jkaczman added this pull request to stack #2012 November 11, 2026 14:23
@jkaczman
jkaczman force-pushed the jk-bench-lru-fixed-seed branch from 13b6db7 to f18e154 Compare November 11, 2026 18:29
@jkaczman
jkaczman force-pushed the jk-bench-lru-fixed-seed branch from f18e154 to a2b6aa9 Compare November 11, 2026 20:54

This branch has not been deployed

No deployments
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