Optimize Decimal::ToIntegerString by replacing stringstream#581
Open
wgtmac wants to merge 2 commits intoapache:mainfrom
Open
Optimize Decimal::ToIntegerString by replacing stringstream#581wgtmac wants to merge 2 commits intoapache:mainfrom
wgtmac wants to merge 2 commits intoapache:mainfrom
Conversation
Replaced std::ostringstream with a manual stack-allocated buffer and std::to_chars to reduce allocation and formatting overhead. Measured a ~3.3x speedup in a standalone benchmark. Correctness verified with focused tests covering boundary cases and round-trip conversions. Co-authored-by: wgtmac <4684607+wgtmac@users.noreply.github.com>
HuaHuaY
reviewed
Feb 27, 2026
src/iceberg/util/decimal.cc
Outdated
Comment on lines
413
to
414
| char buf[48]; | ||
| char* curr = buf; |
Contributor
There was a problem hiding this comment.
Suggested change
| char buf[48]; | |
| char* curr = buf; | |
| std::array<char, 48> buf; | |
| char* curr = buf.begin(); |
I suggest to use std::array instead.
Comment on lines
425
to
432
| for (size_t i = num_segments - 1; i-- > 0;) { | ||
| oss << std::setw(9) << std::setfill('0') << segments[i]; | ||
| uint32_t val = segments[i]; | ||
| for (int j = 8; j >= 0; --j) { | ||
| curr[j] = static_cast<char>(val % 10 + '0'); | ||
| val /= 10; | ||
| } | ||
| curr += 9; | ||
| } |
Contributor
There was a problem hiding this comment.
for (auto val : segments | std::views::take(num_segments - 1) | std::views::reverse) {
for (int j = 8; j >= 0; --j) {
curr[j] = static_cast<char>(val % 10 + '0');
val /= 10;
}
curr += 9;
}Use <ranges> for better readability.
- Optimized Decimal::ToIntegerString by replacing std::ostringstream with a manual stack-allocated buffer and std::to_chars. - Fixed CI failure by adding multiple fallback URLs for nanoarrow 0.7.0, as the original Apache mirror URL was returning 404. - Added missing <charconv> and <ostream> headers. - Added ICEBERG_DCHECK to verify std::to_chars success. Co-authored-by: wgtmac <4684607+wgtmac@users.noreply.github.com>
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.
Replaced std::ostringstream with a manual stack-allocated buffer and std::to_chars in Decimal::ToIntegerString. This eliminates heap allocations and formatting overhead in a common code path.
Measured improvement: ~3.3x speedup (70% reduction in time) in a focused benchmark.
Correctness verified with boundary and round-trip tests.
PR created automatically by Jules for task 4049724441882146694 started by @wgtmac