Skip to content

gh-150889: Improve performance of unicodedata.normalize() - #150890

Merged
serhiy-storchaka merged 3 commits into
python:mainfrom
eendebakpt:gh-149079-find-nfc-index-linear
Jun 6, 2026
Merged

serhiy-storchaka merged 3 commits into
python:mainfrom
eendebakpt:gh-149079-find-nfc-index-linear

Conversation

@eendebakpt

@eendebakpt eendebakpt commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

See the corresponding issue for details.

Scan the nfc_first/nfc_last reindex tables comparing only .start, range-check
the candidate once, and terminate on a sentinel above every codepoint, so each
entry costs a single comparison. ~2x faster on non-Latin and combining-heavy
NFC/NFKC input; no new data tables.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@serhiy-storchaka
serhiy-storchaka self-requested a review June 4, 2026 03:58
@StanFromIreland StanFromIreland changed the title gh-150889: Improve performance of unicode.normalize Jun 4, 2026

@serhiy-storchaka serhiy-storchaka 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.

LGTM. 👍

Please add a NEWS entry and a What's New entry (more than 2x speedup is significant).

@eendebakpt

Copy link
Copy Markdown
Contributor Author

LGTM. 👍

Please add a NEWS entry and a What's New entry (more than 2x speedup is significant).

Added the NEWS entry. Unless the unicodedata.normalize is important in real-world applications (maybe it is, but I do not work with unicode, so I don't know) I would skip the What's New entry. If relevant though, I can add one here or a in followup PR.

@serhiy-storchaka
serhiy-storchaka merged commit 97dea30 into python:main Jun 6, 2026
52 checks passed
philthompson10 pushed a commit to philthompson10/cpython that referenced this pull request Jun 17, 2026
…onGH-150890)

Scan the nfc_first/nfc_last reindex tables comparing only .start, range-check
the candidate once, and terminate on a sentinel above every codepoint, so each
entry costs a single comparison. ~2x faster on non-Latin and combining-heavy
NFC/NFKC input; no new data tables.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants