Repository navigation
perf(export): fast-path _strip_diacritics for ASCII strings and hoist unicodedata import - #5619
Open
Gaurav-meena95 wants to merge 1 commit into
Conversation
… unicodedata import
|
Thanks for the pull request, @Gaurav-meena95. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify review 
No issues reported · High impact
The change moves unicodedata to module scope and returns ASCII strings directly from _strip_diacritics.
Code graph · 1142 functions depend on this change
- 53 of 652 test files are affected by this change.
- Gate, test list and every flagged function: in the Graphify check.
Reviewed 2e98bbe
This branch has not been deployed
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.
What does this PR do?
Adds a pure-C
text.isascii()fast path to_strip_diacritics()and hoistsimport unicodedatato module level ingraphify/export.py, cuttingto_json()runtime nearly in half on large graphs with bit-for-bit identical output.Problem
to_json()calls_strip_diacritics(node.get("label", "")).lower()for every node (norm_label), andto_obsidian()calls it per note. On a ~28.3k-node graph,_strip_diacritics()importedunicodedataper call and ranunicodedata.normalize("NFKD", ...)+"".join(c for c in nfkd if not unicodedata.combining(c))(~1.21M generator iterations) on pure-ASCII strings where NFKD decomposition is an identity operation.Details
graphify/export.pyimport unicodedata+ unconditional NFKD +combining()loopimport unicodedata+if text.isascii(): return texttests/test_export.py_strip_diacriticsASCII fast path vs accented Unicodetest_export_strip_diacritics_ascii_fast_path_and_unicode_foldingNone,int, and diacritic folding behaviourBenchmark
Measured
to_json()ongraphify-out/graph.json(28,540,252bytes output):to_json()0.935s0.473sType of change
How was this tested?