Repository navigation
Conversation
Merged
`$utils.date.format` made a new `Intl.DateTimeFormat` for each call with options, and making one is slow: 20,000 calls took ~570 ms. It now keeps one formatter for each locale and set of options, keyed with the options in key order, so 20,000 calls take ~17 ms. Content can choose the options, so it keeps at most 100 and drops the oldest first. Each call gives the same text as before. Closes #62
The bench site formatted its dates with its own `$utils.humanDate`, so it never ran `$utils.date.format`. It now uses the built-in, as a real site would, and writes the same bytes.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #62. Stacked on #64.
$utils.date.format(value, options)made a newIntl.DateTimeFormaton each call with options, and making one is slow. It now keeps one formatter for each$site.langand set of options. The key has the options in key order, so{ month, year }and{ year, month }share one. Content can choose the options, so it keeps at most 100 formatters, and drops the oldest first. Each call gives the same text as before.The bench site now formats its dates with
$utils.date.format, as a real site would, and not with its own helper. Its output does not change.Benchmark
20,000 calls with
{ dateStyle: 'long' }: about 570 ms before, about 17 ms now.bun run bench site, interleaved A/B against #63 on an M1 Max with Bun 1.4.3: two rounds each, median of 5 runs per round. Both sides used the same bench site, with$utils.date.formatin its date partial.rendering pagesstageThe build writes the same bytes.
Tests: 2 new tests, for one formatter across key orders and for the limit of 100. All 808 pass,
tsc -p .andtsc -p buildare clean, andbun run buildpasses.