Skip to content

perf(export): fast-path _strip_diacritics for ASCII strings and hoist unicodedata import - #5619

Closed
Gaurav-meena95 wants to merge 1 commit into
Graphify-Labs:v8from
Gaurav-meena95:perf/export-strip-diacritics-ascii-fastpath
Closed

Gaurav-meena95 wants to merge 1 commit into
Graphify-Labs:v8from
Gaurav-meena95:perf/export-strip-diacritics-ascii-fastpath

Conversation

@Gaurav-meena95

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds a pure-C text.isascii() fast path to _strip_diacritics() and hoists import unicodedata to module level in graphify/export.py, cutting to_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), and to_obsidian() calls it per note. On a ~28.3k-node graph, _strip_diacritics() imported unicodedata per call and ran unicodedata.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

Target Previous Updated Rationale
graphify/export.py Per-call import unicodedata + unconditional NFKD + combining() loop Module-level import unicodedata + if text.isascii(): return text ASCII strings contain no combining marks and are invariant under NFKD
tests/test_export.py No direct unit test for _strip_diacritics ASCII fast path vs accented Unicode Added test_export_strip_diacritics_ascii_fast_path_and_unicode_folding Pin ASCII, None, int, and diacritic folding behaviour

Benchmark

Measured to_json() on graphify-out/graph.json (28,540,252 bytes output):

Metric Before After Delta
to_json() 0.935s 0.473s -49.4% (~2x faster)

Type of change

  • Refactor / Performance
  • Tests or CI

How was this tested?

uv run pytest tests/test_export.py tests/test_export_control_characters.py -q
uv run ruff check graphify/export.py tests/test_export.py
PATH="$(pwd)/.venv/bin:$PATH" uv run pre-commit run --all-files
uv run graphify update .

@github-actions

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 29, 2026

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Graphify review View in Graphify

Looks safe to merge · Merge confidence 5/5

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

safishamsi added a commit that referenced this pull request Nov 30, 2026
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]>
@safishamsi

Copy link
Copy Markdown
Member

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. 🙏

@safishamsi safishamsi closed this Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants