Skip to content

[IMP] core: add lru on babel_locale_parse#250888

Closed
fw-bot wants to merge 1 commit intoodoo:18.0from
odoo-dev:18.0-17.0-memoise-locales-xmo-500673-fw
Closed

[IMP] core: add lru on babel_locale_parse#250888
fw-bot wants to merge 1 commit intoodoo:18.0from
odoo-dev:18.0-17.0-memoise-locales-xmo-500673-fw

Conversation

@fw-bot
Copy link
Copy Markdown
Contributor

@fw-bot fw-bot commented 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).

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

  1. Cache validity of a locale name python-babel/babel#1254 has been submitted to fix this issue

@robodoo
Copy link
Copy Markdown
Contributor

robodoo commented Feb 26, 2026

Pull request status dashboard

@robodoo robodoo added forwardport This PR was created by @fw-bot conflict There was an error while creating this forward-port PR labels Feb 26, 2026
@fw-bot
Copy link
Copy Markdown
Contributor Author

fw-bot commented Feb 26, 2026

@xmo-odoo cherrypicking of pull request #249795 failed.

stdout:

Auto-merging odoo/tools/misc.py
CONFLICT (content): Merge conflict in odoo/tools/misc.py

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.

⚠️ after resolving this conflict, you will need to merge it via @robodoo.

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
@xmo-odoo xmo-odoo force-pushed the 18.0-17.0-memoise-locales-xmo-500673-fw branch from 00cf261 to 586f6eb Compare February 26, 2026 11:13
@xmo-odoo
Copy link
Copy Markdown
Collaborator

@robodoo r+

@C3POdoo C3POdoo requested review from a team, HydrionBurst and kmagusiak and removed request for a team February 26, 2026 12:32
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>
@robodoo robodoo closed this Feb 26, 2026
@fw-bot fw-bot deleted the 18.0-17.0-memoise-locales-xmo-500673-fw branch March 5, 2026 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflict There was an error while creating this forward-port PR forwardport This PR was created by @fw-bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants