Repository navigation
perf(runtime): reuse rounded digits in native F32 formatting - #1591
Merged
Lorenzobattistela merged 1 commit intoOct 16, 2026
Merged
Conversation
Lorenzobattistela
approved these changes
Oct 16, 2026
Merged
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.
Native
F32.showfinds the shortest round-trip precision with scientific notation. For many values in fixed decimal notation, it then callssnprintfagain. That second call repeats the decimal conversion and rounding.Reuse the rounded digits and move the decimal point instead. For example, turn
1.25e-01into0.125without a second conversion. Keep the precision search, notation thresholds, special values, and scientific-notation path unchanged.The change adds 11 net lines to
comp.ts. The regression test covers decimal-point positions, signs, negative zero, notation thresholds, large values, infinity, and NaN.Measured complete CSV exports (milliseconds):
Fixed decimal workloads used 7.9–18.5% less total time on macOS and 8.7–13.6% less on Linux. The scientific path is unchanged. Its small timing increase does not establish a regression.
Each program exports 200,000 generated rows with an integer index and three F32 columns. Each version ran 15 times in alternating order. The table gives the median after excluding the first two runs. Timing includes the native process and output to a pipe read by Python; it excludes compilation. Runs used
--threads 1 --gpu off. All 120 outputs per platform had matching before/after hashes within each workload.Both environments used an Apple M5 Max and Bun 1.3.14. macOS used Apple clang 21.0.0. Linux ran in an OrbStack ARM64 VM with Debian 13, glibc 2.41, and Clang 19.1.7. The baseline was
d2aeefc1902d617340e26f7fab5c1ef50fe28efa.Validation:
[1, 2), two million pseudorandom bit patterns, and 5,120 exponent/mantissa boundary cases.bun gates/repo.ts: 54/54.git diff --check: passed.Linux x86-64, CUDA, and the full test/performance cluster were not tested.
Waveform CSV workload
Save this as
/tmp/f32-csv.bend:Build it from each checkout. Use a separate output path for each version:
Run this Python script after both builds. It uses the same timing method as the table: