You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On pinned Perry 9495bfc, localeCompare costs 7.80x Node on ASCII and 6.30x on Unicode, because locale_compare_default allocates two fresh lowercased Strings on every single comparison. Inside a sort that cost is paid O(n log n) times. It also orders by code point rather than by collation weights, so "ä".localeCompare("😀") returns -1 where Node returns 1, and the sort-objects-locale-key-unicode checksum diverges from Node. That ordering divergence is now an accepted, intentional limitation — see the scope note below. Do not try to fix it. This issue is the allocation cost plus making the documentation honest.
Measured against Node v26.5.1 using Perry perry 0.5.1531 at 9495bfc95e2afcfb5a7cb535e440e61ec0722cb1. This is evidence from that pinned revision, not a claim that current main was remeasured. First reproduce on current main; if it is already fixed, identify the fixing commit and attach the comparison.
Measurements
Times are median milliseconds per workload invocation. Ratios are Perry/Node. A correctness or timeout classification takes precedence over performance; successful smaller-size timings on those rows are diagnostic evidence.
string-locale-compare-ascii — SLOW
n
Node ms / status
Perry ms / status
ratio
Node checksum
Perry checksum
100
0.002963
0.029381
9.92×
734908598
734908598
1000
0.033858
0.293159
8.66×
408710883
408710883
10000
0.398906
2.951738
7.40×
420981723
420981723
100000
3.830729
29.636333
7.74×
370082741
370082741
1000000
38.291083
297.125833
7.76×
532146590
532146590
Log(time)/log(n) least-squares slopes: Perry 1.001, Node 1.028, delta -0.026.
Workload: ascii variant. n counts repeated input tokens, not bytes; UTF-16 length and UTF-8 byte length differ for Unicode. String result hashes sample roughly 32 positions for long strings (at most 63 for short strings), plus length. n seeded short labels, explicit en-US locale; checksum normalizes comparison result to sign as the API specifies.
string-locale-compare-unicode — SLOW
n
Node ms / status
Perry ms / status
ratio
Node checksum
Perry checksum
100
0.008799
0.056051
6.37×
734908598
734908598
1000
0.089800
0.576973
6.43×
408710883
408710883
10000
0.878049
5.655084
6.44×
420981723
420981723
100000
8.975472
57.779750
6.44×
370082741
370082741
1000000
90.106000
571.383666
6.34×
532146590
532146590
Log(time)/log(n) least-squares slopes: Perry 1.002, Node 1.002, delta -0.000.
Workload: unicode variant. n counts repeated input tokens, not bytes; UTF-16 length and UTF-8 byte length differ for Unicode. String result hashes sample roughly 32 positions for long strings (at most 63 for short strings), plus length. n seeded short labels, explicit en-US locale; checksum normalizes comparison result to sign as the API specifies.
sort-objects-locale-key-unicode — CORRECTNESS
n
Node ms / status
Perry ms / status
ratio
Node checksum
Perry checksum
100
0.087271
0.441680
5.06×
466836667
953887857
1000
1.205924
5.521489
4.58×
54763927
77095570
10000
16.192312
69.037083
4.26×
828669467
731022764
100000
231.026458
934.027792
4.04×
391157046
371047858
1000000
3812.927583
TIMEOUT
—
155096472
—
Log(time)/log(n) least-squares slopes: Perry 1.107, Node 1.156, delta -0.049.
Workload: n objects; keys and original ids are fully hashed in order. Default-locale ordering may differ because Perry documents approximate collation; report mismatches as correctness findings.
Slopes cover different completed sizes: Node [100, 1000, 10000, 100000, 1000000], Perry [100, 1000, 10000, 100000].
perry n=1000000: TIMEOUT, exit -9
Process exceeded 60 s
What is expected / acceptance criteria
Do not change the ordering. Confirm before and after that sort-objects-locale-key-unicode still produces Perry's existing checksum at every size — this issue must be behaviour-preserving for ordering. A change to the sorted order, in either direction, means the fix has overstepped.
Remove both per-comparison to_lowercase() allocations from locale_compare_default, comparing case-folded characters in a single walk that short-circuits at the first difference. Rerun string-locale-compare-ascii and string-locale-compare-unicode at 100, 1k, 10k, 100k and 1M and show the ratio improves from its current 7.80x/6.30x; report the sort-objects-locale-key-unicode timing too, since a sort pays this cost O(n log n) times.
Prove the comparator is a strict weak ordering with a randomized test over a corpus spanning ASCII, Latin-1 accented characters, CJK, emoji, combining marks and lone surrogates: antisymmetry (sign(cmp(a,b)) === -sign(cmp(b,a))), transitivity across triples, and cmp(a,a) === 0. An inconsistent comparator makes Array.prototype.sort results implementation-dependent, which is a real bug even when the ordering is approximate.
Preserve canonical equivalence, which the existing doc comment calls a mandatory part of the contract: decomposed and precomposed forms of the same string must compare equal. Also cover case-only differences (lowercase before uppercase, per the current tertiary pass), empty strings, identical strings, one string a prefix of the other, and strings differing only after a long common prefix.
Make the limitation public and accurate. Rewrite the js_string_locale_compare doc comment to state the actual guarantee — case-insensitive code-point ordering with a case tiebreak, no collation weights, no locale tailoring, ordering will differ from Node for accented letters, symbols and emoji — and say that this is intentional rather than unimplemented.
Fix the public parity table in docs/typescript-parity-gaps.md: the localeCompare() row currently reads "Missing (needs Intl)", which is incorrect. It should say the method is implemented with approximate ordering and no collation table, and link this issue. While there, check the neighbouring toLocaleLowerCase() / toLocaleUpperCase() row for the same staleness and correct it if it is also wrong.
Implementation to inspect
Hypothesis:Scope decision, already made — read this before starting. Matching Node's ordering requires a Unicode collation table (DUCET / CLDR root weights). Perry has decided not to ship one: the data cost is not justified by the use, and docs/typescript-parity-gaps.md already records the reasoning for the namespace as a whole ("Full Intl — requires ICU data (~27MB) or system ICU linkage"). So the correct ordering is explicitly out of scope, and the sort-objects-locale-key-unicode checksum is expected to stay divergent from Node. Do not hand-tune weights, special-case scripts, or otherwise chase that checksum — overfitting a comparator to one benchmark's keys is worse than the honest approximation, and will be rejected in review.
What this issue asks for is the cost and the honesty.
The cost.locale_compare_default in compare.rs begins with let a_lower = a_str.to_lowercase(); let b_lower = b_str.to_lowercase(); and compares those with String::cmp. Two heap allocations and two full Unicode case-mapping passes, per comparison, discarded immediately. Only when the lowercased forms are equal does it fall through to a per-character tertiary pass that orders by case. Both allocations are avoidable: the primary pass can compare case-folded characters as it walks the two strings, short-circuiting at the first difference, without materializing either lowercased string. Most comparisons differ within the first few characters, so the current code does O(n) allocation and case-mapping work to answer a question that usually needs O(1) reads.
The honesty. The doc comment above js_string_locale_compare says "We don't ship a true ICU collator", which is accurate but buried. Worse, the public parity table in docs/typescript-parity-gaps.md lists the localeCompare() row as "Missing (needs Intl)" — which is simply wrong: the method exists, returns sensible answers for most inputs, and is used. A reader deciding whether Perry fits their application currently cannot learn what it actually does.
For context on what the approximation costs in practice, the reduced diagnostic below shows the measured divergence, and the shape of the gap is: code point order sorts accented letters after the entire plain alphabet (ä is U+00E4, above z at U+007A) and sorts symbols and emoji last, whereas root collation groups accented letters with their base letter and sorts symbols before letters. Note also that the "right" answer is locale-dependent even with a table — German sorts ä with a, Swedish sorts it after z — which is further reason the single-table approach was not worth its bytes here.
Source reading narrows the investigation; it does not establish exclusive runtime/compiler attribution. No compiler or runtime changes were made to obtain these measurements.
Agent scope and coordination
Owner scope is locale_compare_default and js_string_locale_compare in crates/perry-runtime/src/string/compare.rs, plus the two documentation updates. Note the interaction with crates/perry-runtime/src/string/slice_ops.rs: the cost being removed here comes from to_lowercase(), the same Unicode case-mapping machinery the separate toLowerCase/toUpperCase ASCII fast-path task is changing. Check that task before starting — if it lands an all-ASCII predicate or a case-folding helper, reuse it rather than writing a second one; if this task lands first, say on the issue what helper you added. Do not add a collation table, an ICU dependency, or per-locale tailoring under this issue; that decision has been made and reversing it is a separate conversation, not a pull request.
Implementation work can proceed in separate branches. Serialize benchmark runs on any shared host; parallel timing runs invalidate small performance comparisons. Preserve language semantics and moving-GC safety.
Everything needed for the workload is embedded below; no private repository, fixture, npm package, or shared prelude is required. Save a complete benchmark block under its indicated filename in /tmp/perry-builtin-repro/. Use Node 26.5.1 to match this baseline; it runs these TypeScript files directly.
To reproduce the historical baseline, use the pinned commit above in a separate checkout and build the compiler and both libraries there. Repeat compilation for each additional benchmark below. Run this small driver from the same checkout, changing name and sizes for that benchmark:
Record before/after results from the same unchanged source, engine versions and host. The measured driver uses seeded setup outside timers, at least 200 ms AND five warmup runs, then seven samples with at least 20 ms measured work each. Fresh input is prepared before each timer for mutating workloads. The median per-run time is reported, with checksum consistency checked on every invocation. Timeouts cover setup, warmup and sampling, not just one builtin call.
Node: v26.5.1; Perry: perry 0.5.1531; build: release from source.
Compile flag: --no-auto-optimize; compiler and both matching runtime archives were rebuilt together.
The pinned source revision and compiler/runtime/Node artifact hashes were unchanged throughout the sweep.
Load average at measurement start: [58.3896484375, 53.017578125, 57.90087890625]; end: [25.240234375, 30.416015625, 24.8681640625].
Host contention limits precise constant-factor claims; repeat on a quiet host before asserting an improvement.
Timings include timer overhead and checksum calculation. String hashes bound lookup count, not Unicode lookup cost; indexed consumption may also force Node string materialization.
Minimal correctness reductions
locale-compare-order.ts
Normalized default-locale comparison signs for keys present in the sorting workload; locale and timezone match the sweep.
Size meanings and fresh-input policy are in the leading metadata. result_on_stderr for this file: False.
// @runtime {"name": "string-locale-compare-ascii", "category": "strings", "verification": "checksum", "sources": [{"file": "crates/perry-runtime/src/string/compare.rs", "function": "js_string_locale_compare"}], "hypothesis": "Hypothesis: canonical normalization and custom primary/case collation add per-comparison work and may diverge from ICU semantics.", "notes": "ascii variant. n counts repeated input tokens, not bytes; UTF-16 length and UTF-8 byte length differ for Unicode. String result hashes sample roughly 32 positions for long strings (at most 63 for short strings), plus length. n seeded short labels, explicit en-US locale; checksum normalizes comparison result to sign as the API specifies.", "asynchronous": false, "output_stderr": false, "fresh_input": false}// Standalone file. Shared helpers/driver are inlined by common.py.letseed=0x12345678;functionrnd(): number{seed^=seed<<13;seed^=seed>>>17;seed^=seed<<5;return(seed>>>0)/4294967296;}functionnumbers(n: number): number[]{consta: number[]=[];for(leti=0;i<n;i++)a.push(Math.floor(rnd()*1000000));returna;}functionhashArray(a: number[]): number{leth=a.length;for(leti=0;i<a.length;i++)h=(h*31+a[i])%1000000007;returnh;}// Bounded checksum work avoids making string slicing/indexing part of every// string benchmark's asymptotic cost. The workload itself consumes its result.functionhashString(s: string): number{leth=s.length;conststep=Math.max(1,Math.floor(s.length/32));for(leti=0;i<s.length;i+=step)h=(h*31+s.charCodeAt(i))%1000000007;returnh;}functionsetup(n: number): string[]{constchoices=["aBcD"+'a',"aBcD"+'z',"aBcD"+'B',"aBcD"+'7'];constvalues: string[]=[];for(leti=0;i<n;i++)values.push(choices[Math.floor(rnd()*4)]);returnvalues;}functionrun(input: string[]): number{leth=0;for(leti=1;i<input.length;i++){constresult=input[i-1].localeCompare(input[i],'en-US');h=(h*31+(result<0 ? 1 : result>0 ? 2 : 3))%1000000007;}returnh;}// Size is the final argument: both native Perry and Node expose it reliably.constn=Number(process.argv[process.argv.length-1]);if(!(n>0))thrownewError("Expected a positive size argument");functionbenchmarkMain(): void{seed=0x12345678;constpreparedInput=setup(n);letchecksum=0;letseen=false;letwarmMs=0;letwarmRuns=0;while(warmMs<200||warmRuns<5){seed=0x12345678;constinput=preparedInput;conststart=performance.now();constvalue=run(input);constelapsed=performance.now()-start;if(!(elapsed>=0))thrownewError("Invalid monotonic timer");warmMs+=elapsed;warmRuns++;if(seen&&value!==checksum)thrownewError("CORRECTNESS: unstable checksum during warmup");checksum=value;seen=true;}constsamples: number[]=[];letruns=0;for(letsample=0;sample<7;sample++){letelapsed=0;letcount=0;// Mutable workloads prepare fresh input BEFORE each timer; immutable// workloads reuse setup. Neither preparation nor validation is measured.while(elapsed<20){seed=0x12345678;constinput=preparedInput;conststart=performance.now();constvalue=run(input);constduration=performance.now()-start;if(!(duration>=0))thrownewError("Invalid monotonic timer");elapsed+=duration;count++;if(value!==checksum)thrownewError("CORRECTNESS: unstable checksum during sampling");}samples.push(elapsed/count);runs+=count;}// Do not depend on Array.sort to compute the median of a sort benchmark.for(leti=1;i<samples.length;i++){constv=samples[i];letj=i-1;while(j>=0&&samples[j]>v){samples[j+1]=samples[j];j--;}samples[j+1]=v;}console.log(JSON.stringify({name: "string-locale-compare-ascii",category: "strings", n,ms_per_run: samples[3], runs, checksum}));}benchmarkMain();
Size meanings and fresh-input policy are in the leading metadata. result_on_stderr for this file: False.
// @runtime {"name": "string-locale-compare-unicode", "category": "strings", "verification": "checksum", "sources": [{"file": "crates/perry-runtime/src/string/compare.rs", "function": "js_string_locale_compare"}], "hypothesis": "Hypothesis: canonical normalization and custom primary/case collation add per-comparison work and may diverge from ICU semantics.", "notes": "unicode variant. n counts repeated input tokens, not bytes; UTF-16 length and UTF-8 byte length differ for Unicode. String result hashes sample roughly 32 positions for long strings (at most 63 for short strings), plus length. n seeded short labels, explicit en-US locale; checksum normalizes comparison result to sign as the API specifies.", "asynchronous": false, "output_stderr": false, "fresh_input": false}// Standalone file. Shared helpers/driver are inlined by common.py.letseed=0x12345678;functionrnd(): number{seed^=seed<<13;seed^=seed>>>17;seed^=seed<<5;return(seed>>>0)/4294967296;}functionnumbers(n: number): number[]{consta: number[]=[];for(leti=0;i<n;i++)a.push(Math.floor(rnd()*1000000));returna;}functionhashArray(a: number[]): number{leth=a.length;for(leti=0;i<a.length;i++)h=(h*31+a[i])%1000000007;returnh;}// Bounded checksum work avoids making string slicing/indexing part of every// string benchmark's asymptotic cost. The workload itself consumes its result.functionhashString(s: string): number{leth=s.length;conststep=Math.max(1,Math.floor(s.length/32));for(leti=0;i<s.length;i+=step)h=(h*31+s.charCodeAt(i))%1000000007;returnh;}functionsetup(n: number): string[]{constchoices=["ä中😀Ö"+'a',"ä中😀Ö"+'z',"ä中😀Ö"+'B',"ä中😀Ö"+'7'];constvalues: string[]=[];for(leti=0;i<n;i++)values.push(choices[Math.floor(rnd()*4)]);returnvalues;}functionrun(input: string[]): number{leth=0;for(leti=1;i<input.length;i++){constresult=input[i-1].localeCompare(input[i],'en-US');h=(h*31+(result<0 ? 1 : result>0 ? 2 : 3))%1000000007;}returnh;}// Size is the final argument: both native Perry and Node expose it reliably.constn=Number(process.argv[process.argv.length-1]);if(!(n>0))thrownewError("Expected a positive size argument");functionbenchmarkMain(): void{seed=0x12345678;constpreparedInput=setup(n);letchecksum=0;letseen=false;letwarmMs=0;letwarmRuns=0;while(warmMs<200||warmRuns<5){seed=0x12345678;constinput=preparedInput;conststart=performance.now();constvalue=run(input);constelapsed=performance.now()-start;if(!(elapsed>=0))thrownewError("Invalid monotonic timer");warmMs+=elapsed;warmRuns++;if(seen&&value!==checksum)thrownewError("CORRECTNESS: unstable checksum during warmup");checksum=value;seen=true;}constsamples: number[]=[];letruns=0;for(letsample=0;sample<7;sample++){letelapsed=0;letcount=0;// Mutable workloads prepare fresh input BEFORE each timer; immutable// workloads reuse setup. Neither preparation nor validation is measured.while(elapsed<20){seed=0x12345678;constinput=preparedInput;conststart=performance.now();constvalue=run(input);constduration=performance.now()-start;if(!(duration>=0))thrownewError("Invalid monotonic timer");elapsed+=duration;count++;if(value!==checksum)thrownewError("CORRECTNESS: unstable checksum during sampling");}samples.push(elapsed/count);runs+=count;}// Do not depend on Array.sort to compute the median of a sort benchmark.for(leti=1;i<samples.length;i++){constv=samples[i];letj=i-1;while(j>=0&&samples[j]>v){samples[j+1]=samples[j];j--;}samples[j+1]=v;}console.log(JSON.stringify({name: "string-locale-compare-unicode",category: "strings", n,ms_per_run: samples[3], runs, checksum}));}benchmarkMain();
Size meanings and fresh-input policy are in the leading metadata. result_on_stderr for this file: False.
// @runtime {"name": "sort-objects-locale-key-unicode", "category": "sort", "verification": "checksum", "sources": [{"file": "crates/perry-runtime/src/array/sort.rs", "function": "js_array_sort_with_comparator"}, {"file": "crates/perry-runtime/src/string/compare.rs", "function": "js_string_locale_compare"}, {"file": "crates/perry-runtime/src/string/compare.rs", "function": "locale_compare_default"}], "hypothesis": "Hypothesis: locale_compare_default compares newly lowercased Rust strings lexicographically with String::cmp instead of applying ICU locale collation weights, which may explain different ordering and checksums for umlaut, CJK and emoji keys.", "notes": "n objects; keys and original ids are fully hashed in order. Default-locale ordering may differ because Perry documents approximate collation; report mismatches as correctness findings.", "asynchronous": false, "output_stderr": false, "fresh_input": true}// Standalone file. Shared helpers/driver are inlined by common.py.letseed=0x12345678;functionrnd(): number{seed^=seed<<13;seed^=seed>>>17;seed^=seed<<5;return(seed>>>0)/4294967296;}functionnumbers(n: number): number[]{consta: number[]=[];for(leti=0;i<n;i++)a.push(Math.floor(rnd()*1000000));returna;}functionhashArray(a: number[]): number{leth=a.length;for(leti=0;i<a.length;i++)h=(h*31+a[i])%1000000007;returnh;}// Bounded checksum work avoids making string slicing/indexing part of every// string benchmark's asymptotic cost. The workload itself consumes its result.functionhashString(s: string): number{leth=s.length;conststep=Math.max(1,Math.floor(s.length/32));for(leti=0;i<s.length;i+=step)h=(h*31+s.charCodeAt(i))%1000000007;returnh;}functionmakeStrings(n: number): string[]{consttokens: string[]=["ä","Ö","漢","字","😀","🚀"];consta: string[]=[];for(leti=0;i<n;i++)a.push(tokens[Math.floor(rnd()*tokens.length)]+":"+String(Math.floor(rnd()*1000000)));returna;}functionsetup(n: number): {key: string,id: number}[]{constkeys=makeStrings(n);consta: {key: string,id: number}[]=[];for(leti=0;i<n;i++)a.push({key: keys[i],id: i});returna;}functionrun(a: {key: string,id: number}[]): number{a.sort((x,y)=>x.key.localeCompare(y.key));leth=a.length;for(leti=0;i<a.length;i++)h=(h*31+hashString(a[i].key)+a[i].id)%1000000007;returnh;}// Size is the final argument: both native Perry and Node expose it reliably.constn=Number(process.argv[process.argv.length-1]);if(!(n>0))thrownewError("Expected a positive size argument");functionbenchmarkMain(): void{seed=0x12345678;letchecksum=0;letseen=false;letwarmMs=0;letwarmRuns=0;while(warmMs<200||warmRuns<5){seed=0x12345678;constinput=setup(n);conststart=performance.now();constvalue=run(input);constelapsed=performance.now()-start;if(!(elapsed>=0))thrownewError("Invalid monotonic timer");warmMs+=elapsed;warmRuns++;if(seen&&value!==checksum)thrownewError("CORRECTNESS: unstable checksum during warmup");checksum=value;seen=true;}constsamples: number[]=[];letruns=0;for(letsample=0;sample<7;sample++){letelapsed=0;letcount=0;// Mutable workloads prepare fresh input BEFORE each timer; immutable// workloads reuse setup. Neither preparation nor validation is measured.while(elapsed<20){seed=0x12345678;constinput=setup(n);conststart=performance.now();constvalue=run(input);constduration=performance.now()-start;if(!(duration>=0))thrownewError("Invalid monotonic timer");elapsed+=duration;count++;if(value!==checksum)thrownewError("CORRECTNESS: unstable checksum during sampling");}samples.push(elapsed/count);runs+=count;}// Do not depend on Array.sort to compute the median of a sort benchmark.for(leti=1;i<samples.length;i++){constv=samples[i];letj=i-1;while(j>=0&&samples[j]>v){samples[j+1]=samples[j];j--;}samples[j+1]=v;}console.log(JSON.stringify({name: "sort-objects-locale-key-unicode",category: "sort", n,ms_per_run: samples[3], runs, checksum}));}benchmarkMain();
What happened
On pinned Perry 9495bfc,
localeComparecosts 7.80x Node on ASCII and 6.30x on Unicode, becauselocale_compare_defaultallocates two fresh lowercased Strings on every single comparison. Inside a sort that cost is paid O(n log n) times. It also orders by code point rather than by collation weights, so"ä".localeCompare("😀")returns -1 where Node returns 1, and thesort-objects-locale-key-unicodechecksum diverges from Node. That ordering divergence is now an accepted, intentional limitation — see the scope note below. Do not try to fix it. This issue is the allocation cost plus making the documentation honest.Measured against Node
v26.5.1using Perryperry 0.5.1531at9495bfc95e2afcfb5a7cb535e440e61ec0722cb1. This is evidence from that pinned revision, not a claim that current main was remeasured. First reproduce on current main; if it is already fixed, identify the fixing commit and attach the comparison.Measurements
Times are median milliseconds per workload invocation. Ratios are Perry/Node. A correctness or timeout classification takes precedence over performance; successful smaller-size timings on those rows are diagnostic evidence.
string-locale-compare-ascii— SLOWLog(time)/log(n) least-squares slopes: Perry 1.001, Node 1.028, delta -0.026.
Workload: ascii variant. n counts repeated input tokens, not bytes; UTF-16 length and UTF-8 byte length differ for Unicode. String result hashes sample roughly 32 positions for long strings (at most 63 for short strings), plus length. n seeded short labels, explicit en-US locale; checksum normalizes comparison result to sign as the API specifies.
string-locale-compare-unicode— SLOWLog(time)/log(n) least-squares slopes: Perry 1.002, Node 1.002, delta -0.000.
Workload: unicode variant. n counts repeated input tokens, not bytes; UTF-16 length and UTF-8 byte length differ for Unicode. String result hashes sample roughly 32 positions for long strings (at most 63 for short strings), plus length. n seeded short labels, explicit en-US locale; checksum normalizes comparison result to sign as the API specifies.
sort-objects-locale-key-unicode— CORRECTNESSLog(time)/log(n) least-squares slopes: Perry 1.107, Node 1.156, delta -0.049.
Workload: n objects; keys and original ids are fully hashed in order. Default-locale ordering may differ because Perry documents approximate collation; report mismatches as correctness findings.
Slopes cover different completed sizes: Node
[100, 1000, 10000, 100000, 1000000], Perry[100, 1000, 10000, 100000].perry n=1000000: TIMEOUT, exit
-9What is expected / acceptance criteria
sort-objects-locale-key-unicodestill produces Perry's existing checksum at every size — this issue must be behaviour-preserving for ordering. A change to the sorted order, in either direction, means the fix has overstepped.to_lowercase()allocations fromlocale_compare_default, comparing case-folded characters in a single walk that short-circuits at the first difference. Rerunstring-locale-compare-asciiandstring-locale-compare-unicodeat 100, 1k, 10k, 100k and 1M and show the ratio improves from its current 7.80x/6.30x; report thesort-objects-locale-key-unicodetiming too, since a sort pays this cost O(n log n) times.Array.prototype.sortresults implementation-dependent, which is a real bug even when the ordering is approximate.js_string_locale_comparedoc comment to state the actual guarantee — case-insensitive code-point ordering with a case tiebreak, no collation weights, no locale tailoring, ordering will differ from Node for accented letters, symbols and emoji — and say that this is intentional rather than unimplemented.docs/typescript-parity-gaps.md: thelocaleCompare()row currently reads "Missing (needs Intl)", which is incorrect. It should say the method is implemented with approximate ordering and no collation table, and link this issue. While there, check the neighbouringtoLocaleLowerCase()/toLocaleUpperCase()row for the same staleness and correct it if it is also wrong.Implementation to inspect
Hypothesis: Scope decision, already made — read this before starting. Matching Node's ordering requires a Unicode collation table (DUCET / CLDR root weights). Perry has decided not to ship one: the data cost is not justified by the use, and
docs/typescript-parity-gaps.mdalready records the reasoning for the namespace as a whole ("FullIntl— requires ICU data (~27MB) or system ICU linkage"). So the correct ordering is explicitly out of scope, and thesort-objects-locale-key-unicodechecksum is expected to stay divergent from Node. Do not hand-tune weights, special-case scripts, or otherwise chase that checksum — overfitting a comparator to one benchmark's keys is worse than the honest approximation, and will be rejected in review.What this issue asks for is the cost and the honesty.
The cost.
locale_compare_defaultin compare.rs begins withlet a_lower = a_str.to_lowercase(); let b_lower = b_str.to_lowercase();and compares those withString::cmp. Two heap allocations and two full Unicode case-mapping passes, per comparison, discarded immediately. Only when the lowercased forms are equal does it fall through to a per-character tertiary pass that orders by case. Both allocations are avoidable: the primary pass can compare case-folded characters as it walks the two strings, short-circuiting at the first difference, without materializing either lowercased string. Most comparisons differ within the first few characters, so the current code does O(n) allocation and case-mapping work to answer a question that usually needs O(1) reads.The honesty. The doc comment above
js_string_locale_comparesays "We don't ship a true ICU collator", which is accurate but buried. Worse, the public parity table indocs/typescript-parity-gaps.mdlists thelocaleCompare()row as "Missing (needs Intl)" — which is simply wrong: the method exists, returns sensible answers for most inputs, and is used. A reader deciding whether Perry fits their application currently cannot learn what it actually does.For context on what the approximation costs in practice, the reduced diagnostic below shows the measured divergence, and the shape of the gap is: code point order sorts accented letters after the entire plain alphabet (
äis U+00E4, abovezat U+007A) and sorts symbols and emoji last, whereas root collation groups accented letters with their base letter and sorts symbols before letters. Note also that the "right" answer is locale-dependent even with a table — German sortsäwitha, Swedish sorts it afterz— which is further reason the single-table approach was not worth its bytes here.js_string_locale_comparejs_array_sort_with_comparatorlocale_compare_defaultSource reading narrows the investigation; it does not establish exclusive runtime/compiler attribution. No compiler or runtime changes were made to obtain these measurements.
Agent scope and coordination
Owner scope is
locale_compare_defaultandjs_string_locale_compareincrates/perry-runtime/src/string/compare.rs, plus the two documentation updates. Note the interaction withcrates/perry-runtime/src/string/slice_ops.rs: the cost being removed here comes fromto_lowercase(), the same Unicode case-mapping machinery the separate toLowerCase/toUpperCase ASCII fast-path task is changing. Check that task before starting — if it lands an all-ASCII predicate or a case-folding helper, reuse it rather than writing a second one; if this task lands first, say on the issue what helper you added. Do not add a collation table, an ICU dependency, or per-locale tailoring under this issue; that decision has been made and reversing it is a separate conversation, not a pull request.Implementation work can proceed in separate branches. Serialize benchmark runs on any shared host; parallel timing runs invalidate small performance comparisons. Preserve language semantics and moving-GC safety.
Reproduce and remeasure
Everything needed for the workload is embedded below; no private repository, fixture, npm package, or shared prelude is required. Save a complete benchmark block under its indicated filename in
/tmp/perry-builtin-repro/. Use Node 26.5.1 to match this baseline; it runs these TypeScript files directly.From the Perry checkout/branch being evaluated:
To reproduce the historical baseline, use the pinned commit above in a separate checkout and build the compiler and both libraries there. Repeat compilation for each additional benchmark below. Run this small driver from the same checkout, changing
nameandsizesfor that benchmark:Record before/after results from the same unchanged source, engine versions and host. The measured driver uses seeded setup outside timers, at least 200 ms AND five warmup runs, then seven samples with at least 20 ms measured work each. Fresh input is prepared before each timer for mutating workloads. The median per-run time is reported, with checksum consistency checked on every invocation. Timeouts cover setup, warmup and sampling, not just one builtin call.
Environment and limits
macOS-26.5-arm64-arm-64bit-Mach-O; target: native host.v26.5.1; Perry:perry 0.5.1531; build: release from source.--no-auto-optimize; compiler and both matching runtime archives were rebuilt together.[58.3896484375, 53.017578125, 57.90087890625]; end:[25.240234375, 30.416015625, 24.8681640625].Minimal correctness reductions
locale-compare-order.tsNormalized default-locale comparison signs for keys present in the sorting workload; locale and timezone match the sweep.
Compile this reduction with the same command, substituting its filename. Run each engine once; no size argument is needed.
node (SUCCESS):
perry (SUCCESS):
Complete standalone benchmark sources
string-locale-compare-ascii.ts — sizes [100, 1000, 10000, 100000, 1000000]
Size meanings and fresh-input policy are in the leading metadata.
result_on_stderrfor this file:False.string-locale-compare-unicode.ts — sizes [100, 1000, 10000, 100000, 1000000]
Size meanings and fresh-input policy are in the leading metadata.
result_on_stderrfor this file:False.sort-objects-locale-key-unicode.ts — sizes [100, 1000, 10000, 100000, 1000000]
Size meanings and fresh-input policy are in the leading metadata.
result_on_stderrfor this file:False.