Skip to content

Try to hold _cache_lock less in load()#1264

Open
akx wants to merge 1 commit intomasterfrom
faster-load
Open

Try to hold _cache_lock less in load()#1264
akx wants to merge 1 commit intomasterfrom
faster-load

Conversation

@akx
Copy link
Copy Markdown
Member

@akx akx commented Apr 10, 2026

Shouldn't be a need to acquire the lock just to return the already-cached data.

@akx
Copy link
Copy Markdown
Member Author

akx commented Apr 10, 2026

cc @xmo-odoo (re #1254).

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 10, 2026

Codecov Report

❌ Patch coverage is 96.42857% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.03%. Comparing base (dea267e) to head (f064914).

Files with missing lines Patch % Lines
babel/localedata.py 96.42% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1264      +/-   ##
==========================================
- Coverage   92.04%   92.03%   -0.01%     
==========================================
  Files          27       27              
  Lines        4715     4723       +8     
==========================================
+ Hits         4340     4347       +7     
- Misses        375      376       +1     
Flag Coverage Δ
macos-14-3.10 91.08% <96.42%> (-0.01%) ⬇️
macos-14-3.11 91.02% <96.42%> (-0.01%) ⬇️
macos-14-3.12 91.23% <96.42%> (-0.01%) ⬇️
macos-14-3.13 91.23% <96.42%> (-0.01%) ⬇️
macos-14-3.14 91.21% <96.42%> (-0.01%) ⬇️
macos-14-3.8 90.95% <96.42%> (-0.01%) ⬇️
macos-14-3.9 91.01% <96.42%> (-0.01%) ⬇️
macos-14-pypy3.10 91.08% <96.42%> (-0.01%) ⬇️
ubuntu-24.04-3.10 91.10% <96.42%> (-0.01%) ⬇️
ubuntu-24.04-3.11 91.04% <96.42%> (-0.01%) ⬇️
ubuntu-24.04-3.12 91.25% <96.42%> (-0.01%) ⬇️
ubuntu-24.04-3.13 91.25% <96.42%> (-0.01%) ⬇️
ubuntu-24.04-3.14 91.23% <96.42%> (-0.01%) ⬇️
ubuntu-24.04-3.8 90.97% <96.42%> (-0.01%) ⬇️
ubuntu-24.04-3.9 91.03% <96.42%> (-0.01%) ⬇️
ubuntu-24.04-pypy3.10 91.10% <96.42%> (-0.01%) ⬇️
windows-2022-3.10 91.09% <96.42%> (-0.01%) ⬇️
windows-2022-3.11 91.03% <96.42%> (-0.01%) ⬇️
windows-2022-3.12 91.24% <96.42%> (-0.01%) ⬇️
windows-2022-3.13 91.24% <96.42%> (-0.01%) ⬇️
windows-2022-3.14 91.22% <96.42%> (-0.01%) ⬇️
windows-2022-3.8 91.07% <96.42%> (-0.01%) ⬇️
windows-2022-3.9 91.02% <96.42%> (-0.01%) ⬇️
windows-2022-pypy3.10 91.09% <96.42%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Reduces lock contention in babel.localedata.load() by avoiding _cache_lock acquisition on cache hits, while refactoring the locale file reading/parent-merge logic into helpers.

Changes:

  • Add _read_locale_file() and _read_locale_merging() helpers to isolate file I/O and inheritance merging logic.
  • Update load() to use a fast path for cache hits (no lock) and a locked slow path for cache misses (double-checked).
  • Make merge_inherited=False bypass caching (and update the docstring accordingly).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +170 to +172
if not merge_inherited:
return _read_locale_file(name)

Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge_inherited=False now bypasses the cache entirely (and the docstring says it disables caching), which changes behavior compared to earlier versions and is important for avoiding cache poisoning when both merged/unmerged variants are requested. Please add a regression test covering this: (1) calling load(..., merge_inherited=False) should not populate _cache for that locale, and (2) it must not affect subsequent load(...) with the default merge_inherited=True (should still return merged + cached data).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants