Repository navigation
perf(export): fast-path _strip_diacritics for ASCII strings and hoist unicodedata import - #5619
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
Extractor accuracy (Swift #5641, Apex #5627, Python #5647, TypeScript #5604/#5614/#5612, Bash caller-var #5602), GitHub Actions run-step extraction (#5603), incremental correctness (#5634/#5638/#5636), symlink and semantic-cache fixes (#5617/#5618), export/report hardening and perf (#5643/#5644/#5645/#5646/#5619/#5620/#5621), and CLI/docs/skill/install work (#5629/#5628/#5626/#5624/#5623/#5625/#5642/#5583). AST cache schema 59 to 60; Swift/Apex/Python/Bash/GHA inputs re-extract on first build. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Landed in v0.9.124 (just released to PyPI), cherry-picked with your authorship preserved so it shows under your name in the history. Thanks @Gaurav-meena95 for the ASCII fast-path for _strip_diacritics — verified green in the full suite and, where applicable, smoke-tested against the published package. 🙏 |
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?