Skip to content

[Subtask]: Reduce normalized hash-probe and key-preparation CPU cost #30846

Closed as not planned

Description

@aunjgr

Parent Issue

#30838

Detail of Subtask

Evidence reassessment — 2026-10-27

Current delivery/performance status: The scalar probe-geometry candidate improved kernel controls and Q21 but independently regressed Q15 by about 3% in both full-suite and longer targeted runs. It fails the no-regression gate, so no PR was opened. The issue is being closed as not planned, without claiming that future optimizations are impossible. Measurements and decision.

Observed: Historical SF100 FindBatch exclusive user shares are about 34.16%/32.89%/38.77% in Q3/Q4/Q5, 18.40% in Q9 and 20.20% in Q21. Runtime filters, input counts, match rates and layouts differ between engines.

Not yet established: Cost per comparable lookup after normalizing actual probe work, canonical key preparation, load factor, collision chains and locality on current main.

Next discriminating experiment: Use actual caller sizes and matched hit/miss, duplicate, key-width and table-occupancy distributions. Separate hash/key generation from probing and report instructions/CPU per equivalent operation alongside total operator work.

Measured target: Unchanged Q3-Q5/Q9/Q21 plus equal-work lookup benchmarks, with attributable cost-per-probe and query improvement.

Mandatory controls and total cost boundary: Misses, skew, collisions, growth, high/low occupancy, nullable/composite keys, tiny/empty calls and admission failure. Include setup, metadata and unsupported paths.

Performance acceptance and rejection

  • Freeze current-main/candidate sources, executables, real caller shapes and effective settings. Use the unchanged qualification SQL and complete result consumption; exclude cold runs and keep profiles separate from latency scoring.
  • Demonstrate the named work/CPU reduction and an attributable uninstrumented target-query improvement. Include the controls below and full Q1-Q22 comparison; component wins, source changes, functional tests, SCA, merging and profile percentages are separate evidence.
  • A confirmed affected/control slowdown fails; unresolved slower signals are inconclusive. Confirm with an independent longer balanced run. No gain elsewhere, favorable average or self-approved tolerance waives a regression.
  • Complete applicable SF10/SF100 and memory/mixed-I/O acceptance before issue closure under the umbrella protocol. Report uncertainty, absolute CPU/instructions/work, allocations/copies and the same whole-application budget, effective cache, I/O/spill/swap/pressure evidence. Benchmark scripts do not verify input/table/schema/row counts/reference results/checksums.

Semantics and lifecycle requirements retained

  • Provide matched-work CPU/instruction benchmarks with hit/miss, collision, duplicate, load-factor, skew and key-width controls.
  • Focused tests cover collisions, NULL/key encoding, growth/admission failure and reset/reuse; query operators retain their existing cancellation and ownership contracts.
  • Profiles demonstrate reduced cost per equivalent probe/key-preparation operation, followed by unchanged Q3–Q5/Q9/Q21 query measurements.
  • Report effects independently from runtime-filter or join-order reductions and from high-cardinality aggregate update changes.

Describe implementation you've considered

Evaluate existing layout/batched probing, bounded prefetch or reuse of canonical work only after identifying the dominant cost. Do not add per-probe proof/prefetch/index work that loses on hits, tiny calls or cache-resident tables.

Coordination: Keep reductions in probe count under #30844 distinct from kernel gains. Reuse #27753 canonical transport rather than duplicating it.

Additional information

Pinned implementation / plan references

Activity

  1. self-assigned this
    on Oct 22, 2026
  2. added
    severity/s0
    on Oct 22, 2026
  3. aunjgr commented on Oct 27, 2026

    @aunjgr
    ContributorAuthor

    Local-only four-lane first-slot lookup experiment: rejected; no PR. The optimization issue remains open.

    The private candidate (2372b88e4b) loads four first cells independently, resolves common hit/empty lanes inline, and calls a collision-tail helper only when needed. Hash generation, zero-marker behavior, insertion/growth/admission, table encoding and prehashed lookup are unchanged. Comparison base: 2465dae7a4ada1b277113cca5afff6fe10149b96; the subsequently fetched main change is Python SDK only, so it does not change this engine/test closure. No optimizer, SUM or #31034 changes are included.

    Matched normal Go1.27.1, GOAMD64=v3 / GOEXPERIMENT=simd, identical fixtures and observable output stores on both sides. CPU0/GOMAXPROCS1; six balanced compiler-free process pairs; the first result in each process is discarded. No input/result verification in benchmark scripts.

    The 36-case matrix loses across tested cache-resident hit/miss/duplicate/collision shapes. Its nominal table sizes are32,16384 and1048576 entries; the repeat-probe fixture is cache-resident and is not evidence of random DRAM lookup performance. Removing an out-of-line common-lane resolver reduced the initial loss but did not pass acceptance.

    Independent longer confirmation (1 second per selected case, six balanced pairs):

    Cache-resident hit control Main median (ns/batch) Candidate median (ns/batch) Paired change 95% ratio-change interval
    entries=32/rows=1/hit 2.9425 3.4770 +18.15% +17.31% to +18.41%
    entries=32/rows=256/hit 337.5000 354.2000 +4.95% +2.90% to +5.01%

    No allocation change. Hashtable/hashmap/hashjoin correctness suites pass. The confirmed cache-resident/control losses block publication; a hypothetical large/random-table gain cannot waive them. No target-query/TPC-H acceptance or SF100 result is claimed, and no benchmark MO service is held.

    A separate bounded local SF10 diagnostic pass sampled actual lookup and aggregate call shapes, without instrumenting either candidate or scoring diagnostic timing. Its combined-query reservoir does not establish per-query weighted work or intrinsic MO-versus-DuckDB table cost. The next design still needs matched real-work profiling and a cheaper common path before another prefetch/lane mechanism is proposed. Performance verification for this task is local only.

    Follow-up local diagnosis, warm runs: In the original binary, Go already inlines both findCell and cellAt into FindBatch. The four-lane variant grows FindBatch from 414 to 1,977 bytes and its stack frame from 24 to 168 bytes; disassembly shows the four hashes, positions and intermediate values being spilled and reloaded. The hit fixture repeats 32 keys in a 1,024-cell table, so it exercises hot, collision-free first slots with precomputed hashes.

    For a separate warm 256-row profile, instructions per operation fell about 8%, but cycles rose about 5–6%. A further matched counter profile recorded about 263 versus 1,414 dispatched stores per batch and about 45% more backend-stalled dispatch slots; L1 data-cache read misses stayed negligible. That is consistent with the generated stack traffic overwhelming the instruction savings on this hot workload. The one-row case takes the scalar tail but still pays the enlarged function's setup: its profile showed about 13% more instructions and 18% more cycles.

    These counters and roughly 2,000 CPU samples per binary are diagnostics on the frozen Go 1.27.1 builds. They are separate from the six-pair latency confirmation and do not establish performance for a cold/random table or unchanged TPC-H queries.

  4. aunjgr commented on Oct 27, 2026

    @aunjgr
    ContributorAuthor

    Local current-main experiment for this issue: Int64HashMap.FindBatch candidate cfc4fbaa23 binds the stable block geometry once per batch while retaining the sequential probe, collision, wrap and output order. Baseline is 1231f06468. This is independent of the SUM candidate and does not change the query plan.

    In the matched owner matrix, 31 of 36 cases showed faster signals, none showed a slower signal, and allocations were unchanged. A separate warm 256-row profile on a 16,384-entry table measured about 22% fewer cycles and 25% fewer instructions per batch. The earlier four-lane implementation remains rejected.

    Twelve clean SF10 process pairs with three warm calls per query produced the following target-query results. The first call to each query in each process was excluded; paired change is the median per-pair ratio, so it need not equal the ratio of the two displayed marginal medians.

    Query Main median Candidate median Paired change 95% interval
    Q3 0.376 s 0.373 s -1.12% -2.39% to +0.56%
    Q4 0.296 s 0.300 s +0.51% -0.50% to +2.14%
    Q5 0.373 s 0.372 s -1.61% -2.49% to +3.52%
    Q9 0.707 s 0.707 s -1.13% -1.93% to +0.39%
    Q21 1.372 s 1.367 s -0.88% -1.92% to +0.21%

    All five intervals cross zero. A separate, preregistered Q21 confirmation used six independent balanced pairs and nine warm calls per arm: main 1.367 s, candidate 1.350 s, -0.97% paired, 95% interval -2.36% to -0.53%. Separate Q9/Q21 CPU profiles showed respectively 2.8% and 3.2% fewer whole-application instructions; these are single profile pairs, not latency scores.

    All 36 retained target and Q21-confirmation arms used eight physical cores, a 16 GiB CN cache and a 32 GiB application cap; every arm had zero measured physical I/O, spill and application swap. Maximum conservative application footprint was 19.15 GiB. Overlapped or interrupted whole pairs were excluded and rerun. The query worker executes and drains results without input, schema, row, reference, result or checksum verification. SF100 was not measured locally.

    The full local Q1–Q22 regression check is running. No PR or issue-closure decision is claimed until it and the required review/static gates finish.

    Full-query timing update: Six clean local SF10 Q1–Q22 pairs have now completed. Q15 is the only query with a slower interval: main median 0.399 s, candidate median 0.415 s, paired change +2.99% (95% interval +2.55% to +4.10%). Q2, Q9, Q13 and Q21 showed faster signals; these gains cannot offset a confirmed Q15 regression. The 12 retained full-suite arms all passed the host and all-memory resource checks; peak conservative application memory was 23.69 GiB and measured physical I/O, spill and application swap were zero. CPU profiles and independent longer Q4/Q15 confirmations are still running. No PR acceptance is claimed while the Q15 signal is unresolved.

  5. aunjgr commented on Oct 27, 2026

    @aunjgr
    ContributorAuthor

    Closing as not planned because the measured candidate fails the required no-regression gate. This does not prove that all future probe optimizations are impossible; a different implementation can reopen the issue with full-query evidence.

    The scalar geometry-hoisting candidate cfc4fbaa23 is a real component optimization: 31/36 matched owner cases showed faster signals, none showed a slower signal, and a separate 256-row profile measured about 22% fewer cycles and 25% fewer instructions. An independent Q21 check also showed a 0.97% paired latency improvement (95% interval 0.53–2.36% faster).

    However, Q15 regressed in the full local SF10 Q1–Q22 comparison and in an independent longer confirmation:

    Measurement Main median Candidate median Median paired change 95% interval
    Full Q1–Q22, six pairs, three warm calls 0.399 s 0.415 s +2.99% +2.55% to +4.10%
    Independent Q4/Q15, six pairs, nine warm calls 0.374 s 0.382 s +3.03% +0.72% to +7.59%

    The paired change is the median of individual pair ratios; it need not equal the ratio of the two marginal medians. Q15 was slower in all six pairs of each experiment. The independent Q4 interval crossed zero. Q2, Q9, Q13 and Q21 showed faster signals in the full suite, but those gains do not offset the confirmed Q15 regression.

    Separate Q15 profiles did not isolate a definitive cause. In these single profile arms, total user cycles were nearly unchanged and instructions fell 2.7%; TableScan.evalFilter accounted for 11.9% versus 14.2% of samples. Its normalized generated instruction sequence is identical, but its entry moved by 32 bytes between the two binaries. This is consistent with an indirect code-layout effect, not proof of one. The full recordings and per-query timing/resource evidence will be linked separately for further analysis.

    All retained full-suite and confirmation arms used eight physical CPUs, a 16 GiB CN cache and a 32 GiB whole-application cap. They recorded zero physical I/O, spill and application swap; peak conservative application memory was 23.69 GiB. Interrupted or overlapping whole pairs were excluded and rerun. First query calls were excluded as warmups. The worker executed and drained queries without input, schema, row, reference, result or checksum verification. SF100 was not measured locally. Owning hashtable/hashmap/hashjoin tests, focused race tests and scoped static checks passed. No production PR was opened.

  6. aunjgr commented on Oct 27, 2026

    @aunjgr
    ContributorAuthor

    Full local SF10 timing table

    Six balanced process pairs, three measured warm calls per query per arm after the excluded cold warmup. Clean main 1231f06468, candidate cfc4fbaa23. The worker executed and drained results without input/schema/row/reference/result validation, serialization or result checksums. All 12 retained arms passed the host and all-memory resource gates.

    Query Main median (s) Candidate median (s) Paired change 95% interval Signal
    Q01 1.4396 1.4277 -0.95% -1.61% to +1.74% Inconclusive
    Q02 0.0478 0.0453 -5.75% -8.31% to -2.49% Faster
    Q03 0.3730 0.3689 -0.66% -2.96% to +2.32% Inconclusive
    Q04 0.2918 0.2983 +2.21% -0.16% to +4.47% Inconclusive
    Q05 0.3665 0.3658 +0.67% -1.91% to +3.32% Inconclusive
    Q06 0.2177 0.2143 -1.44% -3.64% to +1.57% Inconclusive
    Q07 0.3446 0.3461 +1.69% -0.90% to +2.38% Inconclusive
    Q08 0.3462 0.3473 -0.28% -3.46% to +4.95% Inconclusive
    Q09 0.7058 0.6828 -2.58% -5.01% to -0.13% Faster
    Q10 0.5661 0.5665 +0.02% -2.80% to +0.83% Inconclusive
    Q11 0.0858 0.0884 +0.83% -6.97% to +9.14% Inconclusive
    Q12 0.4285 0.4291 -0.40% -3.62% to +2.32% Inconclusive
    Q13 0.3287 0.3203 -1.55% -4.61% to -1.12% Faster
    Q14 0.2258 0.2279 +0.71% -0.95% to +2.44% Inconclusive
    Q15 0.3994 0.4151 +2.99% +2.55% to +4.10% Slower
    Q16 0.1083 0.1074 -0.04% -1.76% to +1.72% Inconclusive
    Q17 0.2459 0.2490 +1.77% -2.27% to +4.75% Inconclusive
    Q18 1.0465 1.0488 -0.11% -1.05% to +1.66% Inconclusive
    Q19 0.5881 0.5898 +0.28% -2.21% to +2.91% Inconclusive
    Q20 0.3367 0.3407 +1.58% -1.38% to +3.29% Inconclusive
    Q21 1.3629 1.3377 -1.83% -2.29% to -1.06% Faster
    Q22 0.1099 0.1111 +1.72% -4.12% to +3.05% Inconclusive

    The paired change is the median of individual pair ratios; it need not equal the ratio of the two marginal medians. Q15 was independently confirmed slower in six additional pairs with nine warm calls per query: +3.03% (95% interval +0.72% to +7.59%). Q4’s independent interval crossed zero. No faster query cancels the Q15 regression.

    Separate warm CPU recordings were collected for Q3, Q4, Q5, Q9, Q15 and Q21 for each version. A public upload of the raw recordings and supporting files was rejected by automatic approval review and is pending explicit authorization; the profiles remain available locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/subtaskseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions