Skip to content

perf(vector): use typed views for selected fixed-width copies - #32627

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
aunjgr:perf/typed-fixed-gathers
Nov 12, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
aunjgr:perf/typed-fixed-gathers

Conversation

@aunjgr

@aunjgr aunjgr commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #32385

What this PR does / why we need it:

Use the existing typed selected-copy helper for non-NULL, nonconstant 4-byte and 8-byte payloads in vector.unionT. Establish typed source and destination views once per append, reducing repeated byte-offset arithmetic and bounds checks in bulk selections.

Copy raw uint32/uint64 payload bits while the existing append path owns alias/COW handling, capacity admission, selection order and repetitions, destination prefixes, and NULL/grouping/provenance metadata. The typed views borrow the existing backing memory and preserve floating-point and decimal bit patterns.

Add dense and sparse selection benchmarks over preallocated off-heap vectors. Reuse the existing fixed-selection correctness and ownership suite. Owning vector tests, targeted SIMD-mode checks, and the full repository default-mode pre-push static checks passed.

@aunjgr
aunjgr requested a review from XuPeng-SH as a code owner November 12, 2026 10:27
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

aunjgr commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Scope and interpretation

This PR changes only the non-NULL 4/8-byte selected payload copy loop. Bulk component instruction reductions are 15.1% (4 bytes) and 19.1% (8 bytes) at 256 selected rows. The earlier dense prototype measured 28.1%/35.1% reductions for 7,782 selected rows; those are component results. Actual TPC-H gather calls average roughly 19–27 selected rows in Q5/Q15, and the loop accounts for a small fraction of each complete query.

One-row controls use about 2.8%/2.3% more instructions; the requester explicitly prioritized bulk copying and accepted this tradeoff. Dense/sparse controls report 0 Go B/op and 0 allocations/op.

SF100 Total +1.88% wall time is accepted by the requester as jitter. Every per-query result, including the Q16 +15.8% median, is retained below. The actual sum of retired instructions across all five complete warm SF100 suites decreases 0.207%; the sum of query-median CPU times decreases 0.28%, and warm application peak decreases 40.61 → 40.36 GiB.

Method

One local process per build/configuration, one excluded complete cold Q1–Q22 suite, then five complete warm suites with profiling/accounting. No benchmark-time row/result/checksum verification. All 32 CPUs, GOGC=100, 16 GiB CN shared cache, 48 GiB application and aggregate/join spill thresholds, 52 GiB parent limit, application swap disabled. No spill/swap/OOM in accepted measurements.

Tables use per-query medians; Total sums those medians. Actual complete-suite instruction totals are reported separately. Repetitions within a process are not independent process pairs. Instruction counters cover the MO server; CPU, memory and I/O cover the application cgroup.

Measured clean normal binaries: main bbfc12bab4f410c26dbf06aa694acba51aba1734, candidate 3aa1c0f62e3a5dd2d00d914efbbd059fa3279be9. Publication head merges authoritative main b0c61f3c77; the vector, types, MPool, shuffle and module inputs remain identical to their measured versions.

SF10 memory

Query Main wall s Candidate wall s Change Main CPU s Candidate CPU s Main instructions G Candidate instructions G
Q1 0.2024 0.2015 -0.4% 6.009 5.911 69.872 69.877
Q2 0.0303 0.0295 -2.7% 0.446 0.443 2.764 2.756
Q3 0.0967 0.0955 -1.2% 2.247 2.166 10.466 9.719
Q4 0.0645 0.0631 -2.2% 1.561 1.559 11.629 11.627
Q5 0.0750 0.0728 -2.8% 1.634 1.591 9.904 9.838
Q6 0.0300 0.0301 +0.4% 0.689 0.638 3.920 3.901
Q7 0.0816 0.0795 -2.5% 2.036 1.804 9.930 8.939
Q8 0.2122 0.2188 +3.1% 2.056 2.083 13.673 13.935
Q9 0.2322 0.2308 -0.6% 5.217 5.295 38.538 39.597
Q10 0.1921 0.1873 -2.5% 4.638 4.501 27.075 27.053
Q11 0.0359 0.0338 -5.9% 0.573 0.563 4.321 4.320
Q12 0.1000 0.0816 -18.4% 2.517 2.206 17.192 16.048
Q13 0.2293 0.2287 -0.2% 6.380 6.374 45.394 45.481
Q14 0.0770 0.0779 +1.2% 1.219 1.164 9.284 9.269
Q15 0.1503 0.1470 -2.2% 1.832 1.795 13.055 12.965
Q16 0.1321 0.1252 -5.2% 1.478 1.366 8.136 8.095
Q17 0.0675 0.0652 -3.4% 1.718 1.690 14.195 14.194
Q18 0.3116 0.3012 -3.3% 6.143 5.693 22.766 22.810
Q19 0.1136 0.1124 -1.0% 2.817 2.776 25.172 25.167
Q20 0.1743 0.1604 -8.0% 4.135 3.749 18.948 17.539
Q21 0.3038 0.3001 -1.2% 7.890 7.888 69.849 71.199
Q22 0.0479 0.0467 -2.5% 1.004 1.023 9.428 9.356
Total 2.9602 2.8894 -2.4% 64.241 62.280 455.512 453.686

Raw slower wall medians: Q6, Q8, Q14.
main bbfc12bab4: five suite wall totals 3.044, 2.988, 2.933, 2.978, 2.952 s; historical cgroup maximum 24.17 GiB (not warm-only); warm physical reads 0.000 GiB; external CPU 0.00 cores, interrupts 0.37 cores; no spill/swap/OOM.
combined 3aa1c0f62e: five suite wall totals 2.944, 2.902, 2.922, 2.906, 2.917 s; historical cgroup maximum 26.40 GiB (not warm-only); warm physical reads 0.000 GiB; external CPU 0.00 cores, interrupts 0.35 cores; no spill/swap/OOM.

Initial SF10 disk; page-policy diagnostic below

Query Main wall s Candidate wall s Change Main CPU s Candidate CPU s Main instructions G Candidate instructions G
Q1 0.2021 0.2112 +4.5% 5.887 5.936 69.871 69.881
Q2 0.0295 0.0297 +0.8% 0.419 0.458 2.756 2.763
Q3 0.0985 0.0953 -3.2% 2.388 2.189 11.565 9.721
Q4 0.0646 0.0638 -1.3% 1.590 1.584 11.678 11.677
Q5 0.0769 0.0799 +3.9% 1.706 1.732 9.961 9.888
Q6 0.0292 0.0300 +2.9% 0.649 0.669 3.920 3.900
Q7 0.0779 0.0807 +3.7% 1.842 1.901 8.974 9.317
Q8 0.2092 0.2223 +6.3% 2.045 2.121 13.846 14.103
Q9 0.2363 0.2300 -2.6% 5.361 5.129 39.652 38.495
Q10 0.1887 0.1930 +2.3% 4.550 4.538 27.037 27.008
Q11 0.0342 0.0362 +6.0% 0.562 0.556 4.322 4.319
Q12 0.0896 0.0863 -3.7% 2.390 2.201 17.218 16.051
Q13 0.2260 0.2385 +5.5% 6.377 6.410 45.679 45.331
Q14 0.0758 0.0731 -3.5% 1.175 1.179 9.268 9.265
Q15 0.1580 0.1526 -3.4% 1.859 1.787 13.064 12.963
Q16 0.1240 0.1273 +2.7% 1.360 1.403 8.116 8.102
Q17 0.0678 0.0706 +4.0% 1.749 1.747 14.200 14.207
Q18 0.3019 0.3454 +14.4% 5.756 6.356 22.856 21.867
Q19 0.1150 0.1119 -2.7% 2.815 2.784 25.172 25.183
Q20 0.1652 0.1687 +2.2% 3.785 3.970 17.800 17.811
Q21 0.3168 0.3192 +0.7% 8.168 8.044 71.256 71.179
Q22 0.0488 0.0469 -3.8% 1.012 1.027 9.432 9.353
Total 2.9357 3.0126 +2.6% 63.445 63.721 457.643 452.383

Raw slower wall medians: Q1, Q2, Q5, Q6, Q7, Q8, Q10, Q11, Q13, Q16, Q17, Q18, Q20, Q21.
main bbfc12bab4: five suite wall totals 2.985, 2.914, 2.921, 2.947, 2.979 s; peak application 15.70 GiB; warm physical reads 0.000 GiB; external CPU 0.00 cores, interrupts 0.34 cores; no spill/swap/OOM.
combined 3aa1c0f62e: five suite wall totals 3.055, 2.995, 3.049, 2.995, 2.991 s; peak application 15.73 GiB; warm physical reads 0.000 GiB; external CPU 0.00 cores, interrupts 0.38 cores; no spill/swap/OOM.

SF100 disk, uncompressed temporary clones

Query Main wall s Candidate wall s Change Main CPU s Candidate CPU s Main instructions G Candidate instructions G
Q1 4.9343 4.9372 +0.1% 97.668 97.140 1059.430 1063.416
Q2 0.4281 0.4277 -0.1% 6.145 6.147 38.390 38.520
Q3 2.6082 2.6182 +0.4% 43.235 42.860 213.446 207.506
Q4 2.0814 2.1201 +1.9% 36.564 35.982 229.635 228.484
Q5 2.5327 2.5450 +0.5% 42.853 42.697 194.883 195.060
Q6 1.0931 1.1043 +1.0% 17.174 16.265 113.522 113.086
Q7 2.7645 2.8329 +2.5% 40.310 40.231 193.601 193.466
Q8 2.4889 2.5655 +3.1% 38.360 38.342 211.658 211.196
Q9 4.8308 4.9258 +2.0% 98.936 100.049 554.386 550.795
Q10 3.7089 3.7239 +0.4% 75.945 75.405 497.524 499.352
Q11 0.4971 0.4909 -1.2% 6.789 6.626 48.787 47.941
Q12 2.8834 3.0202 +4.7% 51.175 51.414 402.119 402.690
Q13 3.1577 3.2788 +3.8% 83.045 86.594 506.601 504.701
Q14 1.9723 1.9978 +1.3% 25.441 24.920 150.185 148.209
Q15 3.4260 3.4667 +1.2% 47.386 47.537 248.661 247.474
Q16 0.5856 0.6781 +15.8% 11.026 11.258 64.789 64.525
Q17 2.6212 2.7446 +4.7% 35.963 35.416 224.574 224.428
Q18 5.4348 5.5424 +2.0% 95.030 93.161 372.075 371.977
Q19 4.3986 4.4739 +1.7% 69.719 68.935 606.486 606.607
Q20 3.4308 3.4728 +1.2% 56.262 55.657 232.202 230.067
Q21 7.4886 7.5948 +1.4% 124.026 123.198 917.350 917.456
Q22 0.5353 0.5396 +0.8% 12.169 12.242 98.455 97.772
Total 63.9023 65.1012 +1.9% 1115.222 1112.075 7178.760 7164.728

Raw slower wall medians: Q1, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10, Q12, Q13, Q14, Q15, Q16, Q17, Q18, Q19, Q20, Q21, Q22.
main bbfc12bab4: five suite wall totals 68.250, 64.532, 64.241, 63.453, 62.706 s; peak application 40.61 GiB; warm physical reads 737.204 GiB; external CPU 0.00 cores, interrupts 0.68 cores; no spill/swap/OOM.
combined 3aa1c0f62e: five suite wall totals 69.294, 66.389, 65.039, 64.044, 63.169 s; peak application 40.36 GiB; warm physical reads 756.306 GiB; external CPU 0.00 cores, interrupts 0.68 cores; no spill/swap/OOM.

Measurement corrections and causal controls

The initial SF100 disk-main arm was excluded by the unchanged two-core interference guard. Btrfs Zstd I/O workers consumed CPU outside the application cgroup. Both fresh SF100 arms used uncompressed task-owned clones (NOCOMPRESS, physical copies) and passed the original guard; raw datasets, loaded seeds, host mount settings and thresholds were unchanged. The failed arm is retained and is not used in the comparison above.

The original SF10-memory peak observer reopened memory.peak after resetting it. This kernel scopes that reset to the same open descriptor, so the old 24.17/26.40 GiB values are historical maxima. A resource-only correction retained the descriptor and measured 21.480 → 21.103 GiB warm peak. Original latency and instruction measurements were retained.

The original SF10-disk Q18 median increased 0.3019 → 0.3454 s, with lower user instruction work but higher kernel CPU and more page faults/fewer huge-page allocations. A process-local control disabled transparent huge pages equally for both arms: Q18 then measured 0.3433 → 0.3336 s. Main's kernel CPU changed from 1.361 to 1.963 s in that control; no production copy code changed. This supports a page-allocation explanation for the original gap.

Q8's original disk sampled non-GC cycles decreased 39.226 → 38.917 G, while GC cycles increased 3.504 → 5.707 G. Separate instruction-sampling diagnostics also found no increased Q8 foreground instruction work.

SF100 Q16's median includes candidate GC in warm runs 1/4 and a page-fault burst in run 2. The full samples are:

Warm suite Main wall s Candidate wall s Main instructions G Candidate instructions G Main faults Candidate faults
1 0.7119 0.7885 64.789 66.510 422369 412632
2 0.6018 0.7206 64.671 64.525 251697 327169
3 0.5767 0.5838 64.499 64.249 240495 244251
4 0.5856 0.6781 68.971 70.848 237579 245998
5 0.5719 0.5625 66.415 63.945 237505 220853

Q16 instruction medians are 64.789 → 64.525 G (−0.41%). The final warm sample is 0.5719 → 0.5625 s. A focused cache/TLB counter diagnostic, retaining all 22 queries and equal page policy, measured approximately 0.3% fewer Q16 instructions with similar LLC/TLB miss counts; the earlier large CPU-cycle gap did not reproduce at the same amplitude. These are causal diagnostics and do not replace the original five warm latency samples.

Allocation/copy accounting (separate instrumented builds)

The copy/store probes include shuffle stores in both arms, so moving a loop into the helper does not manufacture byte savings. Counts describe instrumented Go sites, not all runtime/native memory traffic. Go allocation totals include Go-backed MPool allocations; MPool totals must not be added to overall Go totals. Concurrent/background activity causes small whole-query count differences; the isolated reused-vector controls allocate zero bytes/objects.

Query Go allocated MiB, main → candidate Go objects, main → candidate MPool allocated MiB, main → candidate Instrumented copy/store GiB, main → candidate
Q1 55.12 → 53.83 334827 → 319381 164.67 → 164.67 21.85272 → 21.85282
Q2 16.99 → 17.14 196855 → 197368 179.34 → 179.37 1.15513 → 1.15528
Q3 40.78 → 41.49 353494 → 356767 296.92 → 296.15 4.79168 → 4.79144
Q4 33.07 → 34.88 227732 → 240639 174.08 → 173.87 4.37508 → 4.37496
Q5 45.79 → 45.35 308166 → 308412 257.61 → 257.50 5.01701 → 5.01721
Q6 30.53 → 30.40 154600 → 154455 16.93 → 16.93 0.45104 → 0.45104
Q7 46.46 → 46.60 321837 → 320845 369.96 → 372.55 4.86752 → 4.86896
Q8 260.94 → 261.91 4201603 → 4209128 227.99 → 227.65 5.18497 → 5.18484
Q9 150.03 → 151.08 2406517 → 2414926 1362.41 → 1363.74 6.94075 → 6.94092
Q10 60.08 → 61.02 689614 → 694005 1286.93 → 1288.44 6.46594 → 6.46719
Q11 23.57 → 24.19 403143 → 408238 179.80 → 179.79 1.12507 → 1.12506
Q12 57.95 → 58.11 324146 → 325682 203.36 → 200.08 7.07225 → 7.07215
Q13 823.68 → 828.70 15141560 → 15138304 1550.43 → 1539.03 5.11467 → 5.11080
Q14 46.35 → 46.41 931735 → 931680 267.61 → 269.55 0.74749 → 0.74875
Q15 48.05 → 48.64 578773 → 587274 331.27 → 331.86 1.46247 → 1.46278
Q16 31.71 → 31.98 522037 → 524822 948.72 → 943.70 1.97887 → 1.97451
Q17 56.59 → 57.23 397666 → 401601 67.60 → 67.60 2.17623 → 2.17623
Q18 45.10 → 41.92 324735 → 294276 1150.16 → 1150.07 4.86117 → 4.86106
Q19 61.22 → 61.88 517159 → 522923 57.10 → 57.10 6.03854 → 6.03856
Q20 116.61 → 118.39 2254715 → 2265348 849.18 → 853.27 3.03233 → 3.03525
Q21 109.23 → 108.51 683388 → 675325 456.19 → 456.80 14.15914 → 14.15998
Q22 15.79 → 16.60 89439 → 96664 212.54 → 211.95 1.62853 → 1.62870
Sum of medians 2175.66 → 2186.25 31363741 → 31388063 10610.81 → 10601.65 110.49861 → 110.49849

Validation: existing TestUnionFixedSelection and the owning vector package passed, including both selection index widths, exact bit patterns, NULL/grouping controls, prefixes/repeated/reordered selections, borrowed windows, source mutation and self-append growth. Targeted SIMD-mode molint passed. Full default-mode pre-push SCA passed (molint, license headers/dependencies, golangci-lint). Opt-in SIMD full SCA separately reports two unchanged vector-index unsafe imports on both clean main and this branch; this PR adds no SIMD source or build-tag changes.

@matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label Nov 12, 2026
@mergify

mergify Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@mergify

mergify Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🛑 Queue command cancelled

Queue requested — the merge queue status continues in this comment ↓.

@XuPeng-SH

XuPeng-SH commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 74661e5cf318de062681c8c6972f5264c0e42a08

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mo-bot review · mo-bot-local · review

Commit: 74661e5cf318de062681c8c6972f5264c0e42a08

Assessment: approve

Reusing the existing typed gather simplifies copying while preserving append ownership, payload bits and metadata. No actionable defects found.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

Validation:

  • Isolation preflight passed; native inputs and retained artifacts verified.

  • Full vector package passed: 397 root tests and 1,928 subtests. Focused selection coverage and four batch-consumer tests also passed.

  • Baseline/candidate benchmarks completed; all 300 samples reported zero allocations.

  • Source remained unchanged. Discussion coverage, receipts and logs reconciled in validation-audit.json.

Limitations:

  • Benchmark timings remained noisy, including unchanged controls; no general speedup or regression established.

  • Broader TPC-H and full static-suite results were assessed as supplied author reports, without independent reruns.

@mergify

mergify Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

queue

🛑 Pull request from fork cannot be queued

Details

This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
The author needs to enable "Allow edits from maintainers" on this pull request.

2 similar comments
@mergify

mergify Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

queue

🛑 Pull request from fork cannot be queued

Details

This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
The author needs to enable "Allow edits from maintainers" on this pull request.

@mergify

mergify Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

queue

🛑 Pull request from fork cannot be queued

Details

This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
The author needs to enable "Allow edits from maintainers" on this pull request.

@mergify mergify Bot added the queued label Nov 12, 2026
@mergify

mergify Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

❌ Left the queue · checks failed

1 h 17 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Thu 12 Nov, 14:54 · rule main · triggered by rule Automatic queue on approval for main
  • ❌ Checks failed · in place
  • 🚫 Left the queue 16:12 · b1878da

The failure is in this pull request. It failed tested alone on top of main.

Reason

The merge conditions cannot be satisfied due to failing checks

  • CI Required

To get back in the queue

  • Push a fix: the pull request is queued again once its queue conditions match.
  • If the failure is a flake, tick the box below to queue it again as it is.

Merge conditions not met when it left the queue

  • any of · required by GitHub branch protection:
    • check-neutral = CI Required
    • check-skipped = CI Required
    • check-success = CI Required

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request
2 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection

Times in UTC · dashboard · how the merge queue works

This branch had an error being deployed

1 failed deployment
ci — 3ea2f0c0 Deployed Nov 12, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants