Repository navigation
Perf: Allocation-free readBigDecimal() fast path for small DECIMAL/NUMERICAL values - #2975
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2975 +/- ##
============================================
+ Coverage 59.11% 59.12% +0.01%
- Complexity 5015 5025 +10
============================================
Files 153 153
Lines 36332 36339 +7
Branches 6644 6647 +3
============================================
+ Hits 21476 21487 +11
Misses 11093 11093
+ Partials 3763 3759 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request optimizes the DECIMAL/NUMERIC decode hot path in the JDBC driver by adding an allocation-free fast path to Util.readBigDecimal(), reducing per-cell temporary object creation during ResultSet reads.
Changes:
- Added a fast path that directly assembles small little-endian magnitudes (≤ 8 bytes) into a
longand returnsBigDecimal.valueOf(long, scale)without allocating a reversedbyte[]or creating an intermediateBigInteger. - Preserved the existing
BigInteger-based fallback path for larger magnitudes (and for 8-byte magnitudes that do not fit in a positive signedlong).
Mahendra Chavan (machavan)
approved these changes
Jul 17, 2026
Divang Sharma (divang)
approved these changes
Jul 20, 2026
Muskan Gupta (muskan124947)
approved these changes
Jul 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR optimizes the per-value
DECIMAL/NUMERICdecoder on the ResultSet read path. It removes the throwaway per-cell allocations (a temporarybyte[]and an intermediateBigInteger) fromreadBigDecimal(), while preserving the exact decoded value and the existing lazy-decoding architecture.On wide-row bulk reads — where every column of every row is decoded — these per-cell temporaries multiply into billions of short-lived objects, creating young-generation GC pressure that shows up as both lower throughput and periodic latency spikes. Targeting the decoder by data type keeps the fix small, self-contained, and provably value-identical.
Measured result on a 601-column × 1M-row × 200-iteration scan with 400 runs (default + fetchSize=512):
Key improvements
DECIMAL/NUMERICvalues without an intermediatebyte[]orBigInteger.Changes
1. Allocation-free fast path for
readBigDecimal()(Util.java)readBigDecimal()decodes everyDECIMAL/NUMERICcolumn. The original reverses the little-endian wire bytes into a freshly allocatedbyte[]and then builds an intermediateBigIntegerbefore constructing theBigDecimal. When the unscaled magnitude fits in along(precision ≲ 18, the common case), assemble it directly from the wire bytes and build the result withBigDecimal.valueOf(long, scale), skipping both allocations. Larger magnitudes fall back to the originalBigIntegerpath unchanged.Net effect: for the common case (precision ≲ 18), two per-cell allocations — the reversed magnitude
byte[]and the intermediateBigInteger— collapse to zero, and the value is built with cheaperlongarithmetic.Safety. Output is value-identical to the original —
BigDecimal.valueOf(long, scale)produces the same compact,long-backedBigDecimalthe original path produces for these magnitudes. A magnitude of ≤ 7 bytes always fits a positive signedlong; an 8-byte magnitude with its top bit set yieldsmagnitude < 0and falls through to the unchanged slow path, which also covers every larger value. The input array is only read, never mutated, so all callers (the reader scratch buffer and the Always Encrypted path) are unaffected.Why this is safe to land
long).BigDecimalthe original path produced for the guarded inputs.Benchmark results
Methodology
SELECT *over a 601-column table mixing numeric, string, decimal, and datetime columnsfetchSize=512Combined (default + 512 fetchSize, 400 runs each)
Testing
readBigDecimal()is already exercised by the existing suites —getBigDecimal/getObjectacrossDECIMAL/NUMERICprecision and scale combinations, NBCROW null handling, packet-boundary spanning reads, and Always Encrypted decimal columns.