Skip to content

Optimize formatToData for large numbers#151

Open
rortan134 wants to merge 1 commit into
barvian:mainfrom
rortan134:optimize-format
Open

Optimize formatToData for large numbers#151
rortan134 wants to merge 1 commit into
barvian:mainfrom
rortan134:optimize-format

Conversation

@rortan134

Copy link
Copy Markdown

What

  • Replaced O(n²) unshift operations with O(n) push + reverse for building the integer parts array, improving scalability for large numbers.

  • Switched string concatenation (+=) to an array-based join('') for valueAsString to minimize reallocations.

Benchmarks

Run on Node.js v22.11.0 (Apple M3, ~3.55 GHz)

  • Small (5 digits): Old 1.76 µs/iter, New 1.71 µs/iter (~3% faster)
  • Medium (8 digits): Old 2.43 µs/iter, New 2.33 µs/iter (~4% faster)
  • Large (12 digits): Old 3.13 µs/iter, New 2.96 µs/iter (~5.4% faster)
  • Very Large (15 digits): Old 3.77 µs/iter, New 3.54 µs/iter (~6.1% faster)
  • Extreme (18 digits): Old 4.44 µs/iter, New 4.15 µs/iter (~6.5% faster)

@vercel

vercel Bot commented Jul 27, 2025

Copy link
Copy Markdown

@rortan134 is attempting to deploy a commit to the Barvian Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant