@formatjs/intl-localematcher 0.10.0 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,41 +1,33 @@
1
1
  # Intl LocaleMatcher
2
2
 
3
- We've migrated the docs to https://formatjs.github.io/docs/polyfills/intl-localematcher.
3
+ [Documentation](https://formatjs.github.io/docs/polyfills/intl-localematcher).
4
4
 
5
- ## Performance
6
-
7
- This package implements a highly optimized three-tier locale matching algorithm that provides excellent performance even with large locale sets (700+ locales).
8
-
9
- ### Benchmark Results
10
-
11
- Benchmarked with 725 CLDR locales on Node.js:
5
+ Best fit uses CLDR language distances, requested-locale ordering and supported
6
+ locale preferences. Lookup uses RFC 4647 prefix matching.
12
7
 
13
- | Scenario | Latency | Throughput | Relative Performance |
14
- | ------------------------------------------------------- | ------- | ---------- | -------------------- |
15
- | **Tier 1: Exact Match** (`en`) | 1.38ms | 730 ops/s | Baseline |
16
- | **Tier 2: 1-level Fallback** (`en-US` → `en`) | 1.39ms | 725 ops/s | 1.01x slower |
17
- | **Tier 2: Maximized Match** (`zh-TW` → `zh-Hant`) | 1.40ms | 720 ops/s | 1.02x slower |
18
- | **Tier 3: CLDR Distance** (`sr-Latn-BA` → `sr-Latn-BA`) | 1.38ms | 730 ops/s | 1.00x slower |
19
- | **Tier 3: Fuzzy Match** (`en-XZ` → `en`) | 1.50ms | 670 ops/s | 1.09x slower |
20
-
21
- ### Real-world Impact
22
-
23
- The optimization in this package resolved [issue #4936](https://github.com/formatjs/formatjs/issues/4936), where `DurationFormat` instantiation was taking **610ms** on React Native/Hermes due to slow locale matching against 700+ auto-loaded locales.
8
+ ## Performance
24
9
 
25
- **After optimization:**
10
+ Canonical tags, maximized locales and supported-list indexes are cached for
11
+ repeated matches. Mutable best-fit arrays remain checked before cache reuse.
12
+ `ResolveLocale` checks Set contents and order before reusing its private snapshot;
13
+ matching that snapshot avoids a second validation scan. Later mutations retain
14
+ first-match ordering and locale-data selection.
26
15
 
27
- - Common case (`en-US`): **1.39ms** per instantiation
28
- - Chinese locales (`zh-TW`): **1.40ms** per instantiation
29
- - Serbo-Croatian locales: **1.38ms** per instantiation
16
+ Keep cold preparation, matching, construction and formatting measurements separate.
30
17
 
31
- **Performance improvement: 439x faster** 🚀
18
+ ## Current measurements
32
19
 
33
- ### Three-Tier Optimization
20
+ Measured 2026-10-31 on Apple M4 Max, macOS arm64, Node 24.14.0 / ICU 78.2; source `56d15e997`. Median of seven warmed rounds.
34
21
 
35
- The algorithm uses three tiers for maximum performance:
22
+ | Operation | TS ops/s | TS full helpers ops/s | Native JS ops/s |
23
+ | ------------------- | -------: | --------------------: | --------------: |
24
+ | best fit en | 917,471† | 62,277† | — |
25
+ | best fit en-US | 470,600 | 72,354 | — |
26
+ | best fit zh-TW | 455,547 | 71,873 | — |
27
+ | best fit sr-Latn-BA | 391,251 | 71,347 | — |
28
+ | best fit en-XZ | 456,567 | 72,177 | — |
29
+ | fresh array | 38,101 | 25,985 | — |
36
30
 
37
- 1. **Tier 1 (Exact Match)**: O(1) Set lookup for exact locale matches
38
- 2. **Tier 2 (Maximization + Fallback)**: Progressive subtag removal with locale maximization
39
- 3. **Tier 3 (CLDR Distance)**: Full UTS #35 Enhanced Language Matching with memoization
31
+ [Methodology and raw results](../../benchmarks/polyfills/README.md).
40
32
 
41
- This design ensures that common cases (exact matches and simple fallbacks) are extremely fast, while complex scenarios (script/region matching, language distances) still perform well.
33
+ Latest full Rust core coverage: [all-polyfill report](../../benchmarks/polyfills/README.md#rust-core-suite).
package/index.d.ts CHANGED
@@ -1,12 +1,9 @@
1
- //#region packages/intl-localematcher/abstract/LookupSupportedLocales.d.ts
2
1
  /**
3
2
  * https://tc39.es/ecma402/#sec-lookupsupportedlocales
4
3
  * @param availableLocales
5
4
  * @param requestedLocales
6
5
  */
7
6
  export declare function LookupSupportedLocales(availableLocales: string[], requestedLocales: string[]): string[];
8
- //#endregion
9
- //#region packages/intl-localematcher/abstract/ResolveLocale.d.ts
10
7
  interface ResolveLocaleResult {
11
8
  locale: string;
12
9
  dataLocale: string;
@@ -19,12 +16,8 @@ export declare function ResolveLocale<K extends string, D extends { [k in K]: an
19
16
  localeMatcher: string;
20
17
  [k: string]: string | null | undefined;
21
18
  }, relevantExtensionKeys: K[], localeData: Record<string, D | undefined>, getDefaultLocale: () => string): ResolveLocaleResult;
22
- //#endregion
23
- //#region packages/intl-localematcher/index.d.ts
24
19
  export interface Opts {
25
20
  algorithm: "lookup" | "best fit";
26
21
  }
27
22
  export declare function match(requestedLocales: readonly string[], availableLocales: readonly string[], defaultLocale: string, opts?: Opts): string;
28
- //#endregion
29
- export {};
30
- //# sourceMappingURL=index.d.ts.map
23
+ export {};