perf(bigint): add recursive division and decimal conversion - #4201
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Coverage Report for CI Build 6561Coverage increased (+0.04%) to 89.244%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4d2cf74b59
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
4d2cf74 to
2fb26a9
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7792079b1e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cef4096652
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 898cfc64da
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Use half-divisor wide digits above 64 limbs so large division inherits Karatsuba's subquadratic behavior, while retaining single-limb and Knuth division for smaller operands. Render large decimal values recursively with squared powers of ten and keep iterative 10^19 conversion at the leaves. Add threshold, boundary, and large benchmark coverage for both paths.
Clone the dividend limbs once and move a logical high-water mark down as quotient blocks are processed. This avoids rebuilding and copying the full unprocessed prefix at every recursive step. Keep DecimalDivisor boxed because stable native backends cannot flatten its value-typed BigInt field, and add unbalanced correctness and benchmark coverage.
Split the fixed-point multiplication into quotient and remainder terms so the StringBuilder capacity estimate remains in range for every nonnegative Int bit length. Cover the previous overflow boundary and Int::max_value against an Int64 oracle on the wide backends.
Compute the ceiling half as bits / 2 + bits % 2 so Int::max_value does not wrap before decimal divisor-table construction. Extend the decimal sizing test to cover both fixed-point estimates against Int64 oracles.
8e2275a to
4a57fd0
Compare
Summary
Intoverflow, and retain boxed decimal-divisor records for stable native-backend compatibilityThere are no public API changes.
Performance
Native release benchmarks at 250,000 digits:
The added 65,536-by-64-limb unbalanced benchmark improves from 29.83 ms with whole-prefix rebuilding to 5.35 ms with the mutable work buffer (5.6x). Its scaling is now linear in the number of quotient blocks rather than quadratic copying of the dividend prefix.
The quotient-width guard restores pidigits at 8,000 digits from 1,237.4 ± 0.8 ms to 795.2 ± 1.9 ms, matching the 795.4 ± 1.0 ms pre-feature baseline. The added 9-by-64-limb narrow-quotient benchmark improves from 489.8 ns on recursive division to 334.6 ns on Knuth D, while balanced and very-wide-quotient results remain unchanged.
The 250,001-digit edigits result was also compared byte-for-byte with Go; both produced SHA-256
2e66b93581445e19afc0d73ca280ba6c68b3637c81b27283acb0da8715b65582.Validation
moon check --deny-warn --target all --warn-list +73moon test bigint --target all(wasm 165/165, wasm-gc 192/192, JS 166/166, native 165/165)moon test --target native(7,420/7,420)moon info --target wasm,wasm-gc,js,native(no.mbtichanges)moon fmt