[IMP] core: add lru on babel_locale_parse#250888
Closed
Conversation
Contributor
Contributor
Author
|
@xmo-odoo cherrypicking of pull request #249795 failed. stdout: Either perform the forward-port manually (and push to this branch, proceeding as usual) or close this PR (maybe?). In the former case, you may want to edit this PR message as well. More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port |
`babel.Locale.parse` checks if a locale is valid by calling `os.path.exists` on the resolved filename for the locale (this is done in `babel.localedata.exists`). It does try a cache before, but that cache is only populated when the locale is actually loaded, but in cases where we instantiate tons of locales but never actually need to load the data this results in tons of redundant calls to `os.path.exists` which never actually reach the cache. X-original-commit: b58f92b
00cf261 to
586f6eb
Compare
Collaborator
|
@robodoo r+ |
robodoo
pushed a commit
that referenced
this pull request
Feb 26, 2026
`babel.Locale.parse` checks if a locale is valid by calling `os.path.exists` on the resolved filename for the locale (this is done in `babel.localedata.exists`). It does try a cache before, but that cache is only populated when the locale is actually loaded, but in cases where we instantiate tons of locales but never actually need to load the data this results in tons of redundant calls to `os.path.exists` which never actually reach the cache. closes #250888 X-original-commit: b58f92b Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
This was referenced Feb 26, 2026
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.

babel.Locale.parsechecks if a locale is valid by callingos.path.existson the resolved filename for the locale (this is done inbabel.localedata.exists).Babel does have a locale cache which it checks, but currently that cache is only populated when the locale is actually loaded1, therefore in cases where we instantiate a significant number of locales but never actually need to load locale data (e.g. formatting a significant number of datetimes, in qweb, using only non-localised patterns) this results in severe FS traffic for no reason.
Forward-Port-Of: #249795
Footnotes
Cache validity of a locale name python-babel/babel#1254 has been submitted to fix this issue ↩