Skip to content

Conversation

@BurntSushi
Copy link
Owner

This more completely unifies unsigned and signed integer
formatting. It also removes an unused option (to force the
printing of the sign) and an unused field.

Interestingly, these changes result in quite a substantial
(relatively speaking) decrease in LLVM lines. In my Biff
benchmark, prior to this PR, we were getting 753,181 LLVM
lines. But with this PR, we get 745,928 LLVM lines.

For compile times on my Biff benchmark (which is just doing
a cargo build and a cargo build --release after a
cargo clean for each), it seems like there's basically
no change. With maybe the release build being a hair faster.

Before this PR:

Benchmark 1: cargo b
  Time (mean ± σ):      4.659 s ±  0.023 s    [User: 15.631 s, System: 2.070 s]
  Range (min … max):    4.618 s …  4.694 s    10 runs

Benchmark 2: cargo b -r
  Time (mean ± σ):      7.770 s ±  0.076 s    [User: 65.860 s, System: 2.556 s]
  Range (min … max):    7.656 s …  7.886 s    10 runs

After this PR:

Benchmark 1: cargo b
  Time (mean ± σ):      4.654 s ±  0.033 s    [User: 15.521 s, System: 2.079 s]
  Range (min … max):    4.606 s …  4.717 s    10 runs

Benchmark 2: cargo b -r
  Time (mean ± σ):      7.651 s ±  0.053 s    [User: 65.295 s, System: 2.560 s]
  Range (min … max):    7.575 s …  7.711 s    10 runs

I don't think we need to keep track of maximum digits separately for
signed and unsigned integer formatting. I think this might mean that
signed integer formatting uses an extra byte of stack space, but, it can
also have a sign. Unlike unsigned integer formatting. So no space is
wasted here.

We also remove the `force_sign` option, which Jiff does not use. And
overall simplify the signed integer formatting to just reuse the
unsigned integer formatting. And also get rid of the dumb
`checked_abs()` usage. Not sure what I was thinking.
It's not used. I believe it was being used when `Decimal` was also
responsible for formatting the fractional part of a floating point
number. But it isn't needed any more.
And similarly for `DecimalFormatter`.

I believe I originally called this `Decimal` because it was also used to
do fractional formatting.
@BurntSushi BurntSushi merged commit 61dc9bd into master Dec 23, 2025
40 checks passed
@BurntSushi BurntSushi deleted the ag/binary-size-tweaks branch December 23, 2025 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants