-
-
Notifications
You must be signed in to change notification settings - Fork 161
size: stop BigInt.prototype.toLocaleString pinning the Intl number formatter #7427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| size: `BigInt.prototype.toLocaleString` no longer pins the ECMA-402 number formatter into programs that never mention `toLocale*` — hello world drops 82,656 bytes (4,874,072 → 4,791,416). |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // `BigInt.prototype.toLocaleString` is the sole retainer of the ECMA-402 | ||
| // number-formatting machinery for programs that never mention `toLocale*`, | ||
| // so the thunk carries an `intl-namespace` cfg split. This file mentions | ||
| // `toLocaleString`, which turns the feature on — it therefore covers the | ||
| // ECMA-402 side of that split: every case below must keep formatting through | ||
| // the real Intl number formatter. | ||
|
|
||
| const big = 9876543210n; | ||
| const small = 42n; | ||
| const negative = -1234567n; | ||
|
|
||
| console.log("en-US:", big.toLocaleString("en-US")); | ||
| console.log("de-DE:", big.toLocaleString("de-DE")); | ||
| // `fr-FR` is deliberately absent: Perry groups it with `,` where Node uses | ||
| // U+202F, a pre-existing separator gap unrelated to this thunk. | ||
|
|
||
| // Under three digits there is no grouping to apply in any locale. | ||
| console.log("small en-US:", small.toLocaleString("en-US")); | ||
| console.log("small de-DE:", small.toLocaleString("de-DE")); | ||
|
|
||
| // The sign must survive grouping. | ||
| console.log("negative en-US:", negative.toLocaleString("en-US")); | ||
|
|
||
| // Options reach the formatter, not just the locale tag. | ||
| console.log( | ||
| "currency:", | ||
| big.toLocaleString("en-US", { style: "currency", currency: "USD" }), | ||
| ); | ||
| console.log( | ||
| "grouping off:", | ||
| big.toLocaleString("en-US", { useGrouping: false }), | ||
| ); | ||
|
|
||
| // Reflective dispatch hits the same thunk as a direct call. | ||
| console.log( | ||
| "reflective:", | ||
| (BigInt.prototype.toLocaleString as any).call(big, "en-US"), | ||
| ); | ||
|
|
||
| // Brand check: a non-BigInt receiver must throw rather than format. | ||
| let threw = false; | ||
| try { | ||
| (BigInt.prototype.toLocaleString as any).call({}); | ||
| } catch { | ||
| threw = true; | ||
| } | ||
| console.log("brand check throws:", threw); |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50370
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 501
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50369
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 43334
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50369
Root
valuearoundglobal_this_rest_array_values(rest).global_this_rest_array_values(rest)allocates aVec<f64>and can reach allocation-point GC. Rootvaluebefore that call and reload it before both formatting branches.🤖 Prompt for AI Agents
Sources: Coding guidelines, Learnings