Skip to content

perf(function): hoist decimal cast invariants - #30880

Merged
mergify[bot] merged 5 commits into
matrixorigin:mainfrom
aunjgr:perf/decimal-cast-invariants
Oct 22, 2026
Merged

mergify[bot] merged 5 commits into
matrixorigin:mainfrom
aunjgr:perf/decimal-cast-invariants

Conversation

@aunjgr

@aunjgr aunjgr commented Oct 22, 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:

Closes #30839

Related to #30838

What this PR does / why we need it:

Implicit decimal casts recomputed the same type/scale proof for every non-NULL row. Wide casts also repeatedly selected the physical width used for scaling. These batch-invariant decisions were a measured Q1 CPU hotspot.

Compute the widening proof, scale delta, width selection and fallback predicates once per batch in the five affected cast kernels. Keep the existing value-dependent scaling, precision checks, rounding, NULL handling, append errors and SQL result metadata. Leave the Decimal64-to-128 array helper unchanged because it already hoists its proof.

Extend the existing precision tests with empty/all-NULL batches, repeated constant values, and scaling boundaries across Decimal64/128/256. Extend the existing microbenchmark with wide and same-scale cases and the existing fast-path control.

Validation:

  • Full function-package tests pass, including all 61 precision-contract cases. Optimized disassembly places the proof/width calls before the row loops.
  • Warm SF10 Q1: 2.075s → 1.666s, 1.245× speedup (paired-bootstrap 95% interval 1.228–1.272). Six balanced process pairs, three timed calls per arm, with priming and per-arm cold warmups excluded.
  • Whole-application CPU: 14.267 → 11.209 CPU s/query. Separate warmed profiles: 275.91 → 219.57 billion user instructions/query; PMU counters ran for 100% of their enabled intervals.
  • Same eight physical cores, 32 GiB application cap including native images on tmpfs, unchanged Q1 SQL and prepared image; zero measured physical I/O, spill events and swap. Benchmark scripts perform no data/schema/row-count/reference/result verification.
  • Cast microbenchmarks use ten balanced single-core pairs and 256 rows/evaluation; for example, same-scale Decimal128-to-256 is 3.017 → 0.917 µs/evaluation. Allocation counts remain unchanged. These component gains are separate from the Q1 measurement.
  • Performance recordings identify baseline 1daa5e459b and candidate 5c9b6e0d8d. Subsequent main merges preserve all five changed decimal kernels; post-merge function tests and the complete static gate are refreshed.
  • Full pre-push make static-check passes in the default CI analysis profile. Functional/performance binaries use optimized GOAMD64=v3 / GOEXPERIMENT=simd.

The end-to-end measurement covers Q1; it does not claim a full TPC-H suite speedup.

@aunjgr aunjgr added the severity/s0 Active / top priority for current sprint. Owner has committed to working on it now. label Oct 22, 2026
@aunjgr aunjgr self-assigned this Oct 22, 2026
@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 →

@XuPeng-SH

XuPeng-SH commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-xupeng · done

Commit: 09a552c50b3bfa84d7bab55fc0733268b260cd95

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-xupeng · review

Commit: 09a552c50b3bfa84d7bab55fc0733268b260cd95

Assessment: approve

Reviewed the complete two-file delta, callers, conversion owners, and test coverage. The hoisting preserves rounding, overflow, NULL, and metadata behavior while improving throughput. No actionable findings.

Model: gpt-6-astra / xhigh

Session: 01a15209-2c6d-71e2-b8f3-aa17387fa283 · slot 2 · generation 0

Validation:

  • Isolation preflight passed. Verified 192 matching native inputs and repository-owned native provenance before testing.

  • All 61 precision cases and three related test functions passed on both the candidate and the merge-base implementation with identical current tests.

  • The complete function package passed: 2,203 top-level tests, with no failures or skips; function-package.log matches receipt 1792692100868710044-3.json.

  • Six alternating benchmark pairs across 11 cases showed 1.97–3.47× speedups in affected cases, unchanged allocations, and approximately 1% variation in unchanged controls.

  • Source cleanliness, command/source/exit receipts, logs, and artifact hashes reconciled in /home/xupeng/.local/state/mo-bot/jobs/3939e7f775253d9972b9d241/attempt-1/validation-report.json; benchmark details are in benchmark-summary.json.

Limitations:

  • Local validation used Linux/amd64, Go 1.27.1, and GOAMD64=v1. Kernel benchmarks do not independently establish the reported end-to-end TPC-H Q1 speedup.

  • Frozen evidence contained CI success statuses but no raw CI or author performance logs, and no linked-issue bodies. The issue contract was assessed from the supplied PR description.

@mergify mergify Bot added the queued label Oct 22, 2026
@mergify

mergify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-22 18:05 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-10-22 19:41 UTC · at 517a0a412ba5f3b52e6abe722c9675a3d72491af · squash

This pull request spent 1 hour 35 minutes 57 seconds in the queue, including 58 minutes 45 seconds running CI.

Required conditions to merge

@mergify
mergify Bot merged commit 517a0a4 into matrixorigin:main Oct 22, 2026
29 of 30 checks passed
@mergify mergify Bot removed the queued label Oct 22, 2026
mergify Bot pushed a commit that referenced this pull request Oct 22, 2026
…ch (#30885)

Use valid Decimal256 operand precision to skip redundant range scans in multiplication dispatch. Precision up to 9 proves an int32 coefficient; precision up to 18 proves int64. Compute proofs once per batch, preserve the int32-before-int64 tier order, and retain dynamic checks for unknown or invalid metadata. Existing multiply, scaling, rounding and result-precision enforcement remain responsible for results and errors. Metadata-free callers retain the original unknown-proof path.

Validation: full function package tests including the newly merged decimal-cast changes, an independent math/big oracle across precision 9/10/18/19, signed values, constants, NULLs, selection and scale rounding, plus existing overflow/wide-path coverage. Public-dispatch 256-row microbenchmarks improve ~1.39x for proven int32 and ~1.20x for proven int64, with zero allocations; wide fallback is unchanged. Query timing is reported separately from kernel gains.

Comparison protocol: optimized SIMD builds, eight physical CPUs, a private retained SF10 native image, 32 GiB application limit including the image, no swap, and a 16 GiB CN SHARED memory cache verified from running-process metrics. Query cold warmups are excluded; CPU profiling is separate from latency. All query evidence uses main with #30880 merged. No dataset or query-result verification runs in benchmark scripts.

Paired SF10 replay on merged main (six balanced process generations, three scored calls per query per arm):

| Query | Main median | Candidate median | Speedup | Paired 95% interval |
|---|---:|---:|---:|---:|
| Q1 | 1.596845 s | 1.601109 s | 0.9973x | 0.9728–1.0219x |
| Q15 | 0.464836 s | 0.457631 s | 1.0157x | 1.0060–1.0249x |

Q1 shows no demonstrated whole-query gain; Q15 shows a modest ~1.6% gain in this replay. All measured windows pass the zero physical I/O, spill, swap, OOM and sustained-memory-pressure gates. These are selected-query results, not a whole-suite or SF100 speedup claim.

Separate CPU/PMU diagnostic (one process generation per variant, two warm query calls, excluded from the latency comparison): user instructions per call 211.846G → 215.195G, user cycles 48.694G → 49.829G. The recordings have no lost samples. This single diagnostic pair is not a significance test or a query speedup claim.

Isolated kernel microbenchmarks used the pre-#30880 main snapshot; that cast-only merge does not change the timed constructor, multiplication or SUM kernel closures. The retained-image query comparisons and profiles were rebuilt and rerun with #30880 included.

Approved by: @XuPeng-SH
XuPeng-SH pushed a commit that referenced this pull request Oct 22, 2026
…30884)

## What type of PR is this?

- [ ] API-change
- [ ] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Related to #30849; umbrella #30838.

[Approved versioned
design](https://github.com/aunjgr/matrixone/blob/0f810e8452/docs/design/tpch-column-cache-attribution.md).

## What this PR does / why we need it:

Attribute repeated decoded-column work to reader write bypasses, cache
admission decisions and column construction. Add fixed per-codec calls,
successful decoded bytes and errors, plus memory-cache update outcomes.
Counters aggregate per block, IOVector or column construction and reset
with the existing CounterSet. Cache policy, capacity, decoding and
ownership remain unchanged.

Make the existing HTML counter reporter load live atomic leaves without
copying enclosing containers or reading atomic fields through
reflect.IsZero. A concurrent writer/reporter regression test reproduced
the old race; the complete perfcounter race suite passes with the fix.

Validation: full perfcounter, fileservice, objectio and readutil package
tests; focused cache/constructor race coverage; cold versus hit
reconstruction, threshold boundary, policy bypass, every admission
rejection stage, codec errors and counter reset tests. Constructor
microbenchmarks show ~79 ns extra for an uncompressed 16 KiB column
(~8.6%) and ~1.6% for LZ4, with unchanged allocations. This is an
attribution step, not a cache-policy optimization.

Comparison protocol: optimized SIMD builds, eight physical CPUs, a
private retained SF10 native image, 32 GiB application limit including
the image, no swap, and a 16 GiB CN SHARED memory cache verified from
running-process metrics. Query cold warmups are excluded; CPU profiling
is separate from latency. All query evidence uses main with #30880
merged. No dataset or query-result verification runs in benchmark
scripts.

With the effective 16 GiB cache, three warm Q6 calls reconstruct 4.03
GiB in 75,516 LZ4 constructions; memory-cache reads/hits are
87,900/12,384, reader-policy bypasses and FileService policy skips are
both 18,879, and no decoded-entry admission attempts or pressure skips
occur in the measured window. Cache use is only ~260 MiB. Q10 similarly
shows 21,279 reader-policy bypasses, 7.21 GiB reconstructed and ~859 MiB
cache use. These counters distinguish policy bypass from insufficient
cache capacity; changing that policy is follow-up work.

Separate CPU/PMU diagnostic (one process generation per variant, two
warm query calls, excluded from the latency comparison): user
instructions per call 18.188G → 18.309G, user cycles 6.476G → 6.406G.
The recordings have no lost samples. This single diagnostic pair is not
a significance test or a query speedup claim.

Isolated kernel microbenchmarks used the pre-#30880 main snapshot; that
cast-only merge does not change the timed constructor, multiplication or
SUM kernel closures. The retained-image query comparisons and profiles
were rebuilt and rerun with #30880 included.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

This branch was previously deployed

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

Labels

kind/enhancement severity/s0 Active / top priority for current sprint. Owner has committed to working on it now. size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Subtask]: Hoist invariant decimal cast metadata and scale proofs out of row loops

3 participants