Repository navigation
perf(export): avoid duplicate read and JSON parse of existing graph.json in to_json - #5646
Gaurav-meena95 wants to merge 2 commits into
Conversation
|
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 
6 possible issues to check · High impact
The change reuses the existing-file parse from the shrink check when checking for hyperedge metadata.
6 possible issues we couldn't confirm
- The perf test counts every json.loads call in the process, so unrelated parsing during to_json would fail it and it can't isolate the graph. ·
tests/test_export.py:1986 - The test named for avoiding duplicate reads only counts JSON parses, so a second read of graph.json would still pass ·
tests/test_export.py:1976 - The stderr check after the force=True write can match output from an earlier call and does not confirm the warning came from the call under ·
tests/test_export.py:1996 - +3 more in Graphify
They don't change the score.
Code graph · 1165 functions depend on this change
- 1 function became more coupled.
to_json()(124 callers). - 54 of 658 test files are affected by this change.
- Gate, test list and every flagged function: in the Graphify check.
Reviewed 433c742 · 2 earlier findings not re-checked
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 avoiding the duplicate graph.json read and parse in to_json — verified green in the full suite and, where applicable, smoke-tested against the published package. 🙏 |
What does this PR do?
Eliminates the duplicate disk read and
json.loads()parse of an existinggraph.jsoninto_json()(graphify/export.py) whenforce=FalseandG.graphhas nohyperedgeskey.Problem
When overwriting an existing
graph.jsonwithforce=Falseand no"hyperedges"key onG.graph,to_json()read and parsed the entiregraph.jsonfile twice:existing_data = json.loads(raw))._prev = json.loads(existing_path.read_text(...))).Details
to_json()(graphify/export.py)json.loads()existinggraph.jsontwice_prev_hyperedges = existing_data.get("hyperedges")during the shrink-guard parse and reuse itforce=True, empty-file, and oversized-file behaviortests/test_export.pytest_to_json_parses_existing_file_only_once_for_guardsforce=Falseandforce=TrueType of change
How was this tested?
Measured on
graphify-out/graph.json(28,629 nodes / 61,344 edges, 28.8 MBgraph.json):json.loadscalls dropped from 2 to 1 (0.787stotal overwrite).