Skip to content

Commit 47d7b07

Browse files
gfxclaude
andcommitted
Remove #[inline] from large functions, add small feature to CI
Drop #[inline] from functions with substantial code (short, parse, parse_text, fmt_float, format_base10, trim_zeros, uscale, unpack64, fixed_width, mul_pow10) to reduce WASM code duplication. Keep it on tiny helpers only. Run tests and clippy for both feature configs in CI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a7495a5 commit 47d7b07

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
- uses: actions/checkout@v6
1818
- uses: dtolnay/rust-toolchain@stable
1919
- run: cargo test --workspace
20+
- run: cargo test --workspace --features small
2021

2122
integrity:
2223
name: Integrity
@@ -28,6 +29,9 @@ jobs:
2829
components: clippy, rustfmt
2930
targets: wasm32-unknown-unknown
3031
- run: cargo check --workspace
32+
- run: cargo check --workspace --features small
3133
- run: cargo check --target wasm32-unknown-unknown
34+
- run: cargo check --target wasm32-unknown-unknown --features small
3235
- run: cargo clippy --workspace -- -D warnings
36+
- run: cargo clippy --workspace --features small -- -D warnings
3337
- run: cargo fmt --all --check

AGENTS.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ The crate is `no_std` and `wasm32-unknown-unknown` compatible.
99
## Development
1010

1111
```sh
12-
cargo test
12+
cargo test && cargo test --features small
1313
cargo fmt
14-
cargo clippy
14+
cargo clippy && cargo clippy --features small
1515
cargo bench -p bench
16+
cargo bench -p bench --features small
1617
```

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ Measured on Apple M3 Pro, macOS 15.7.3 (aarch64):
5555

5656
| Task | fpfmt | fpfmt `small` | ryu | stdlib |
5757
| ------------------------- | -----: | ------------: | -----: | -----: |
58-
| **format** (f64 → string) | 65 ns | 102 ns | 240 ns | 528 ns |
59-
| **parse** (string → f64) | 697 ns | 701 ns || 658 ns |
58+
| **format** (f64 → string) | 63 ns | 99 ns | 239 ns | 529 ns |
59+
| **parse** (string → f64) | 690 ns | 700 ns || 675 ns |
6060

6161
```sh
6262
cargo bench -p bench
@@ -67,8 +67,8 @@ cargo bench -p bench --features small
6767

6868
| Configuration | Size |
6969
| ------------- | --------------: |
70-
| default | 14,428 bytes |
71-
| `small` | **4,224 bytes** |
70+
| default | 14,379 bytes |
71+
| `small` | **4,175 bytes** |
7272

7373
```sh
7474
cargo build --target wasm32-unknown-unknown --release -p wasm-size

src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ const UINT64_POW10: [u64; 20] = [
119119
/// `unpack64` returns (m, e) such that `f = m * 2**e`.
120120
/// The caller is expected to have handled 0, NaN, and +/-Inf already.
121121
/// To unpack an `f32`, use `unpack64(f as f64)`.
122-
#[inline]
123122
#[allow(clippy::many_single_char_names)]
124123
fn unpack64(f: f64) -> (u64, i32) {
125124
const SHIFT: u32 = 64 - 53; // 11
@@ -165,7 +164,6 @@ fn prescale(e: i32, p: i32, lp: i32) -> Scaler {
165164
}
166165

167166
#[cfg(feature = "small")]
168-
#[inline]
169167
#[allow(clippy::many_single_char_names)]
170168
fn mul_pow10(p: i32) -> PmHiLo {
171169
let q = p.div_euclid(K);
@@ -225,7 +223,6 @@ fn prescale(e: i32, p: i32, lp: i32) -> Scaler {
225223
/// `uscale` returns `unround(x * 2**e * 10**p)`.
226224
/// The caller should pass `c = prescale(e, p, log2_pow10(p))`
227225
/// and should have left-justified x so its high bit is set.
228-
#[inline]
229226
fn uscale(x: u64, c: Scaler) -> Unrounded {
230227
let r = u128::from(x) * u128::from(c.pm.hi);
231228
let mut hi = (r >> 64) as u64;
@@ -247,7 +244,6 @@ fn uscale(x: u64, c: Scaler) -> Unrounded {
247244
///
248245
/// Panics if `n > 18`.
249246
#[must_use]
250-
#[inline]
251247
#[allow(clippy::many_single_char_names)]
252248
pub fn fixed_width(f: f64, n: i32) -> (u64, i32) {
253249
debug_assert!(n <= 18, "too many digits");
@@ -270,7 +266,6 @@ pub fn fixed_width(f: f64, n: i32) -> (u64, i32) {
270266
///
271267
/// Panics if `d > 10_000_000_000_000_000_000` (more than 19 digits).
272268
#[must_use]
273-
#[inline]
274269
#[allow(clippy::many_single_char_names)]
275270
pub fn parse(d: u64, p: i32) -> f64 {
276271
debug_assert!(d <= 10_000_000_000_000_000_000, "too many digits");
@@ -294,7 +289,6 @@ pub fn parse(d: u64, p: i32) -> f64 {
294289
/// Parses a decimal string and returns the nearest f64.
295290
/// Returns `None` if the input is malformed.
296291
#[must_use]
297-
#[inline]
298292
pub fn parse_text(s: &[u8]) -> Option<f64> {
299293
fn is_digit(c: u8) -> bool {
300294
c.wrapping_sub(b'0') <= 9
@@ -362,7 +356,6 @@ pub fn parse_text(s: &[u8]) -> Option<f64> {
362356
/// using as few digits as possible that will still round trip
363357
/// back to the original f64.
364358
#[must_use]
365-
#[inline]
366359
#[allow(clippy::many_single_char_names)]
367360
pub fn short(f: f64) -> (u64, i32) {
368361
const MIN_EXP: i32 = -1085;
@@ -411,7 +404,6 @@ fn skewed(e: i32) -> i32 {
411404
/// Removes trailing zeros from `x * 10**p`.
412405
/// If x ends in k zeros, returns `(x/10**k, p+k)`.
413406
/// Assumes that x ends in at most 16 zeros.
414-
#[inline]
415407
#[allow(clippy::unreadable_literal)]
416408
fn trim_zeros(x: u64, p: i32) -> (u64, i32) {
417409
const INV5P8: u64 = 0xc767074b22e90e21; // inverse of 5**8
@@ -472,7 +464,6 @@ const I2A: &[u8] = b"\
472464
/// Formats the decimal representation of u into a.
473465
/// The caller is responsible for ensuring that a is big enough to hold u.
474466
/// If a is too big, leading zeros will be filled in as needed.
475-
#[inline]
476467
fn format_base10(a: &mut [u8], mut u: u64) {
477468
let mut nd = a.len();
478469
while nd >= 8 {
@@ -523,7 +514,6 @@ fn format_base10(a: &mut [u8], mut u: u64) {
523514
/// The caller must pass nd set to the number of digits in d.
524515
/// Returns the number of bytes written to s.
525516
#[must_use]
526-
#[inline]
527517
pub fn fmt_float(s: &mut [u8], d: u64, p: i32, nd: i32) -> usize {
528518
let nd = nd as usize;
529519
// Put digits into s, leaving room for decimal point.

0 commit comments

Comments
 (0)