Repository navigation
Compute plural info once per PO file at compile time - #449
Merged
Merged
Conversation
`compile_po_file/5` derived the plural data twice: once in `nplurals/3` and once in `compile_plural_forms/4`, each calling `Plural.plural_info/3`. That function runs `Code.ensure_compiled!/1` and parses the `Plural-Forms` header, so it is needless work repeated for every PO file across all locales and domains. Compute `plural_info` once in `compile_po_file/5` and pass it to both helpers. The generated code is identical (the same value is escaped into the plural dispatcher and fed to `nplurals/1`); only the duplicate computation is removed.
josevalim
approved these changes
Oct 26, 2026
Contributor
|
Thank you @oliver-kriska 🫶 |
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.
Call
c:Gettext.Plural.init/1once per PO file at compile time, as documented, instead of twice. ComputePlural.plural_info/3once and pass the same value to both the plural-form compiler andnplurals/1. This also emits the deprecatednplurals-only header warning once rather than twice.Split from #445 as requested, based directly on the latest upstream
main. The rebase preserves the literal-map compilation added in #446. This PR does not depend on either of the other two split changes.The implementation-detail CountingPlural test remains removed per José's review. The existing full suite passes: 193 checks (188 tests and 5 doctests) on Elixir 1.20.4/OTP 29 and 1.18.4/OTP 27, with compilation using
--warnings-as-errorsand formatting checked. All three split changes also combine without conflicts and pass together. No application-wide compile-time speedup is claimed.