Repository navigation
perf(function): avoid EXP overflow error allocations - #28592
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
aptend
left a comment
There was a problem hiding this comment.
Deep review completed at exact head 1e7a6b886d993eecd5d7b5ef48ab2de417fb43cc. I audited the full three-file diff, the referenced #28560 failure, EXP’s prior momath.Exp semantics, the generic null-on-error refactor, constant/vector/NULL/selection paths, result reuse, and the allocation regression. No blocking issue found. The new predicate helper preserves the old callback contract exactly, while EXP replaces only the per-row formatted error with the same math.Exp + infinity decision; finite values, NaN, ±Inf, underflow, input NULLs, constants, and masks retain their behavior. Validation on the exact head: full pkg/sql/plan/function tests pass; focused EXP/COT tests pass five repetitions and under -race; the overflow benchmark is stable at ~78.6–78.8 µs/op, 2040 B/op, 8 allocs/op across three runs; git diff --check passes. GitHub required checks are complete without failures (Darwin/compatibility jobs were skipped by CI routing).
|
Queued — the merge queue status continues in this comment ↓. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review completed at exact head 1e7a6b8.
No confirmed blocker found. The EXP change preserves finite values, overflow-to-NULL, underflow, NaN/Inf behavior, NULLs, constants, selected rows, result reset, and cleanup ownership while removing discarded error/formatting allocations.
Nonblocking test/benchmark cleanup issue: pkg/sql/plan/function/func_builtin_test.go:2755 and :2788 create process memory pools registered in globalPools but never delete them. Repeated test/benchmark invocations retain pool objects until process exit. Register pool deletion after vector/result cleanup.
Validation: exact-head CI run 34436798813 passed Ubuntu UT, SCA, coverage, and active BVT; func_math_exp.test recorded 39/39 and func_math_power.test 101/101. Not independently run: fresh local race/vet, live SQL, fault injection, cancellation measurement, same-instance BVT repetition, mixed-version/downgrade/restore, and benchmarks.
Merge Queue Status
This pull request spent 11 minutes 10 seconds in the queue, with no time running CI. Waiting for any of
All conditions
ReasonPull request #28592 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Tick the box to put this pull request back in the merge queue (same as
|
) ## What type of PR is this? - [x] BUG - [x] Improvement - [ ] API-change - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#28560 ## What this PR does / why we need it: `EXP` overflow is a row-local `NULL`, but the current evaluator obtains that result by constructing a formatted `moerr` for every overflowing row and immediately discarding it. On the 1-billion-row `SUM(EXP(...))` workload this turns expected data-domain rejection into billions of error allocations, stack captures, formatting operations, and GC work. This change adds an error-free unary NULL-check path and makes `EXP` use `math.Exp` plus an infinity check. SQL behavior is unchanged: finite results, underflow, input NULLs, constant inputs, and selection masks retain their existing semantics; overflow still produces NULL. Existing null-on-error callers keep their current error callback contract. A local alloc profile of the unfixed 8192-row all-overflow benchmark attributed 95.5% of benchmark allocation space cumulatively to `momath.Exp` / `NewOutOfRangeNoCtxf`; stack capture was 45.7% and `fmt.Sprintf` was 22.3% of total allocation space. After the change the CPU profile is dominated by the intended `math.Exp` and NULL bitmap work. Benchmark on linux/amd64 (8192 overflowing values per operation): ```text before: 14.54-16.95 ms/op 4,655,216-4,655,552 B/op 81,928-81,929 allocs/op after: 0.103-0.121 ms/op 2,040-2,201 B/op 8 allocs/op ``` The test suite includes an allocation-scaling regression comparing one overflow row with an 8192-row overflow batch. Validation: - `go test ./pkg/sql/plan/function -count=1` - focused EXP/COT tests with `-count=5` - focused EXP/COT tests with `-race` - `go vet ./pkg/sql/plan/function` - `git diff --check` Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
) ## What type of PR is this? - [x] BUG - [x] Improvement - [ ] API-change - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#28560 ## What this PR does / why we need it: `EXP` overflow is a row-local `NULL`, but the current evaluator obtains that result by constructing a formatted `moerr` for every overflowing row and immediately discarding it. On the 1-billion-row `SUM(EXP(...))` workload this turns expected data-domain rejection into billions of error allocations, stack captures, formatting operations, and GC work. This change adds an error-free unary NULL-check path and makes `EXP` use `math.Exp` plus an infinity check. SQL behavior is unchanged: finite results, underflow, input NULLs, constant inputs, and selection masks retain their existing semantics; overflow still produces NULL. Existing null-on-error callers keep their current error callback contract. A local alloc profile of the unfixed 8192-row all-overflow benchmark attributed 95.5% of benchmark allocation space cumulatively to `momath.Exp` / `NewOutOfRangeNoCtxf`; stack capture was 45.7% and `fmt.Sprintf` was 22.3% of total allocation space. After the change the CPU profile is dominated by the intended `math.Exp` and NULL bitmap work. Benchmark on linux/amd64 (8192 overflowing values per operation): ```text before: 14.54-16.95 ms/op 4,655,216-4,655,552 B/op 81,928-81,929 allocs/op after: 0.103-0.121 ms/op 2,040-2,201 B/op 8 allocs/op ``` The test suite includes an allocation-scaling regression comparing one overflow row with an 8192-row overflow batch. Validation: - `go test ./pkg/sql/plan/function -count=1` - focused EXP/COT tests with `-count=5` - focused EXP/COT tests with `-race` - `go vet ./pkg/sql/plan/function` - `git diff --check` Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
) ## What type of PR is this? - [x] BUG - [x] Improvement - [ ] API-change - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#28560 ## What this PR does / why we need it: `EXP` overflow is a row-local `NULL`, but the current evaluator obtains that result by constructing a formatted `moerr` for every overflowing row and immediately discarding it. On the 1-billion-row `SUM(EXP(...))` workload this turns expected data-domain rejection into billions of error allocations, stack captures, formatting operations, and GC work. This change adds an error-free unary NULL-check path and makes `EXP` use `math.Exp` plus an infinity check. SQL behavior is unchanged: finite results, underflow, input NULLs, constant inputs, and selection masks retain their existing semantics; overflow still produces NULL. Existing null-on-error callers keep their current error callback contract. A local alloc profile of the unfixed 8192-row all-overflow benchmark attributed 95.5% of benchmark allocation space cumulatively to `momath.Exp` / `NewOutOfRangeNoCtxf`; stack capture was 45.7% and `fmt.Sprintf` was 22.3% of total allocation space. After the change the CPU profile is dominated by the intended `math.Exp` and NULL bitmap work. Benchmark on linux/amd64 (8192 overflowing values per operation): ```text before: 14.54-16.95 ms/op 4,655,216-4,655,552 B/op 81,928-81,929 allocs/op after: 0.103-0.121 ms/op 2,040-2,201 B/op 8 allocs/op ``` The test suite includes an allocation-scaling regression comparing one overflow row with an 8192-row overflow batch. Validation: - `go test ./pkg/sql/plan/function -count=1` - focused EXP/COT tests with `-count=5` - focused EXP/COT tests with `-race` - `go vet ./pkg/sql/plan/function` - `git diff --check` Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #28560
What this PR does / why we need it:
EXPoverflow is a row-localNULL, but the current evaluator obtains that result by constructing a formattedmoerrfor every overflowing row and immediately discarding it. On the 1-billion-rowSUM(EXP(...))workload this turns expected data-domain rejection into billions of error allocations, stack captures, formatting operations, and GC work.This change adds an error-free unary NULL-check path and makes
EXPusemath.Expplus an infinity check. SQL behavior is unchanged: finite results, underflow, input NULLs, constant inputs, and selection masks retain their existing semantics; overflow still produces NULL. Existing null-on-error callers keep their current error callback contract.A local alloc profile of the unfixed 8192-row all-overflow benchmark attributed 95.5% of benchmark allocation space cumulatively to
momath.Exp/NewOutOfRangeNoCtxf; stack capture was 45.7% andfmt.Sprintfwas 22.3% of total allocation space. After the change the CPU profile is dominated by the intendedmath.Expand NULL bitmap work.Benchmark on linux/amd64 (8192 overflowing values per operation):
The test suite includes an allocation-scaling regression comparing one overflow row with an 8192-row overflow batch.
Validation:
go test ./pkg/sql/plan/function -count=1-count=5-racego vet ./pkg/sql/plan/functiongit diff --check