Skip to content

perf: share repeated source message IDs when reading PO catalogs - #1395

Open
SAY-5 wants to merge 1 commit into
python-babel:masterfrom
SAY-5:fix/po-message-id-sharing-20261018
Open

SAY-5 wants to merge 1 commit into
python-babel:masterfrom
SAY-5:fix/po-message-id-sharing-20261018

Conversation

@SAY-5

@SAY-5 SAY-5 commented Oct 18, 2026 •

Copy link
Copy Markdown

While reading a PO file, PoFileParser now keeps a dict of message ID strings, so an msgid or plural part that appears again in the same file (for example under a different msgctxt) reuses the first string object instead of keeping a duplicate. The dict only lives as long as the parser, so nothing is held globally.

Refs #571.

@akx akx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of using sys.intern, what about just having a temporary dict of these strings within the parser? That would work for free-threaded builds too.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@SAY-5
SAY-5 force-pushed the fix/po-message-id-sharing-20261018 branch from 4e96885 to 4da5393 Compare October 28, 2026 12:36
@SAY-5

SAY-5 commented Oct 28, 2026

Copy link
Copy Markdown
Author

Switched to a dict on the parser, dropped sys.intern and the build check, and cut the tests down to a single case in test_pofile_read.py. It only dedups within one read_po call now (e.g. the same msgid under different contexts), so separately loaded catalogs no longer share IDs.

This branch has not been deployed

No deployments
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