Skip to content

Fix Messagepipe correctness and prepare built-in formatting paths - #2

Merged
Marcisbee merged 7 commits into
mainfrom
kode/3EkbtGt5-improve-messagepipe-performance-and-corr
Oct 28, 2026
Merged

Marcisbee merged 7 commits into
mainfrom
kode/3EkbtGt5-improve-messagepipe-performance-and-corr

Conversation

@Marcisbee

@Marcisbee Marcisbee commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

MessagePipe previously mixed transformers between instances and repeatedly constructed Intl formatters. This change isolates message caches, fixes quoted delimiters, selection/plural behavior, Intl options, relative-time units, and the ESM package entry point.

Built-in pipes prepare literal options once and reuse preparation for up to 16 dynamic primitive-option combinations per pipe. Dynamic arguments still evaluate on every call. Object-valued options retain the generic path. Each prepared number/date/time/plural variant retains at most 100 scalar results, clearing and bypassing its result cache after 100 consecutive misses. Mutable inputs, undefined, and signed zero bypass result caching.

Plural fragments and select choices are prepared once; single-marker plural text uses direct concatenation for strings and numbers. Transformer lookup happens before argument evaluation, preserving JavaScript call order even when getters replace a transformer. Custom transformers receive fresh options, and already-compiled messages observe replacement functions. Invalid Intl options still throw during rendering.

README benchmarks compare equivalent outputs against development-only @messageformat/core 3.4.1. Three independent processes per mode, seven samples each, one million calls per sample after warmup; median across 21 samples. Linux x64/WSL, Ryzen 9 9950X, Node 22.23.2, ICU 78.2, en-GB/UTC:

Workload MessageFormat (ops/s) MessagePipe (ops/s) MessagePipe / MessageFormat
Plain text: Wow 256,043,589 269,588,503 1.05×
Interpolation: Hello {planet} 130,454,294 129,213,173 0.99×
Select: gender pronoun 74,260,093 107,320,883 1.45×
Number: EUR currency 4,548,900 89,069,331 19.58×
Number: dynamic fraction digits 2,184,894 8,686,990 3.98×
Date: day/month/year 2,355,474 86,348,441 36.66×
Plural: item count 4,297,437 86,933,654 20.23×
Workload MessageFormat (ops/s) MessagePipe (ops/s) MessagePipe / MessageFormat
Interpolation: Hello {planet} 167,120,929 168,019,475 1.01×
Number: EUR currency 4,586,144 6,132,395 1.34×
Number: dynamic fraction digits 1,991,615 2,734,228 1.37×
Date: day/month/year 2,305,404 2,684,219 1.16×
Plural: item count 3,337,506 5,730,987 1.72×

Interpolation remains effectively tied; this does not establish strict superiority for every message. Repeated-value gains include result caching. The varied mode covers 1,000 interpolation inputs as well as Intl inputs, exceeding result-cache capacity and exercising bypass. Plain text remains a constant return and interpolation a direct concatenation; neither caches rendered strings. Dynamic digits use pipe arguments in MessagePipe and a select between compiled number skeletons in MessageFormat. Both modes validate outputs and alternate measurement order. Reproduce with npm run benchmark and npm run benchmark -- --varied.

A separate paired before/after check for dynamic digits, using seven samples of 100,000 calls, improved median elapsed time from 105.59 ms to 10.76 ms versus the preceding implementation (9.8×).

Validation: 67 tests, lint, builds, declarations, and CommonJS/ESM imports pass. The getter/transformer ordering regression failed before repair. Coverage includes changing options, mutable option coercion, undefined/null selections, replacement transformers, signed zero, raw output, and native Intl comparisons in four locales. Fetched origin/main; no newer changes required incorporation.

Tradeoffs: preparation adds compile-time work. Each dynamic pipe can retain up to 16 variants with 100 results each. The ESM bundle is approximately 6.4 KB minified, versus 2.8 KB at the original baseline. Cold calls, mutable objects, and other messages/runtimes have different costs. Calendar relative-time units use documented fixed durations. Templates remain trusted expressions compiled with Function. The release lint command and package import checks are fixed; no publication or runtime dependencies are included.

@Marcisbee
Marcisbee marked this pull request as ready for review October 27, 2026 22:33
@Marcisbee Marcisbee changed the title Fix Messagepipe formatting correctness and reuse Intl formatters Fix Messagepipe correctness and prepare built-in formatting paths Oct 28, 2026
@Marcisbee
Marcisbee merged commit 744cfd3 into main Oct 28, 2026
2 checks passed
@Marcisbee
Marcisbee deleted the kode/3EkbtGt5-improve-messagepipe-performance-and-corr branch October 28, 2026 16:07
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