Repository navigation
Conversation
nicolas-grekas
left a comment
There was a problem hiding this comment.
another optim could be to make the caching props static, for worker mode
2acd540 to
cd01fb4
Compare
|
|
||
| if ('rounding_mode' === $name) { | ||
| if (!isset(self::NUMBER_ROUNDING_ATTRIBUTES[$value])) { | ||
| throw new RuntimeError(\sprintf('The number formatter rounding mode "%s" does not exist, known modes are: "%s".', $value, implode('", "', array_keys(self::NUMBER_ROUNDING_ATTRIBUTES)))); |
There was a problem hiding this comment.
should we unset the cache for that hash for such errors ? If no, the cached formatter will still exist, but will have a config that does not match its cache key as applying the config would have been done only partially.
Previously this was fine as the next usage would reach the exception again, without skipping logic.
|
@nicolas-grekas this would be much harder, as the cache key would have to be tied to the config of the prototype formatter (while the whole point of this cache is to skip the introspection that would be needed to build the cache key). Using the object id as cache key would not help for worker mode as the prototype would be recreated as often as the extension in which it is injected. |
…butes, or symbols (nicolas-grekas) This PR was merged into the 3.x branch. Discussion ---------- Don't cache Intl formatters built from long patterns, attributes, or symbols The formatter caches can contain up to 100 entries, but ICU stores the pattern of each date formatter in memory that `memory_limit` doesn't account for. Formatters with a cache key longer than 4 KB are now created on each call instead of being cached. This applies to long patterns, attributes and symbols. #5037 changes the same method, so the PR merged second will need a rebase. Commits ------- 44a3c72 Don't cache Intl formatters built from long patterns, attributes, or symbols
With a `NumberFormatter` prototype, every `format_number` call read 45 attributes, text attributes and symbols from the prototype. It then set all 45 again on the formatter it had just taken from its cache. The prototype is now read once. A formatter is configured only when it is created and cached only once fully configured (everything set is part of its cache key), so a cached formatter is returned as is. `format_number` with a prototype goes from 51.9-64.4 -> 3.5-3.6 µs on PHP 8.4 and from 50.3-51.8 -> 3.1-5.0 µs on PHP 8.5, and without one from 1044-1103 -> 845-879 ns on PHP 8.4 and from 851-945 -> 697-745 ns on PHP 8.5. Caveat: a prototype changed after the extension was constructed is no longer read again.
cd01fb4 to
672c791
Compare
|
PR rebased and conflicts fixed |
With a
NumberFormatterprototype, everyformat_numbercall read 45 attributes, text attributes and symbols from the prototype, then set all 45 again on the formatter it had just taken from its cache.The prototype is now read once, and a formatter is configured only when it is created (everything set is part of its cache key).
format_numberwith a prototype goes from 49.7-55.3 -> 4.0-4.3 µs, and without one from 842-1162 -> 742-773 ns. Caveat: a prototype changed after the extension was constructed is no longer read again.