Repository navigation
perf: a vertex fills its attributes directly in __init__ and add_vertex - #62
Merged
Merged
Conversation
…d graph directly The coordinate hook in Vertex.__setattr__ made every attribute assignment in the constructor and in add_vertex a Python-level call. A vertex that is being made, or added, is in no graph, so there is no spatial index for the hook to invalidate: __init__ now updates __dict__ in one operation and add_vertex writes _name and _graph directly. Assigning coord to a vertex that is in a graph is still seen. add_vertex 3.79 -> 3.12 us, Vertex() 2.06 -> 1.62 us. The attributes are declared on the class so the types are still known, and the duplicate assignment of _edgelist is gone. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 15 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #62 +/- ##
==========================================
+ Coverage 97.18% 97.24% +0.06%
==========================================
Files 3 3
Lines 1562 1560 -2
==========================================
- Hits 1518 1517 -1
+ Misses 44 43 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Vertex.__setattr__(added with the k-d tree in #60) tells the graph whenv.coordis assigned, so that a stale spatial index is never used. It runs on every attribute assignment, including the seven inVertex.__init__and the two inGraph.add_vertex, and cost about 30% on vertex creation.A vertex that is being made or added is in no graph, so there is no index to invalidate:
Vertex.__init__updates__dict__in one operation (with a comment on why), and the attributes are declared on the class so the types are still known. The duplicateself._edgelist = []is gone.add_vertexwrites_nameand_graphdirectly. The name setter does nothing but set_namefor a vertex that is in no graph.v.coord = xandv.coord += xon a vertex that is in a graph.g.add_vertex([0, 0])Vertex([0, 0])12 new tests: the attributes of a new vertex, the coordinate being a copy, subclasses with their own
__init__, the name table and back-pointer, renaming, a refused duplicate leaving the vertex free, and that assigningcoord(=and+=) is still seen while other attributes are not a change. 750 pass, mypy clean.🤖 Generated with Claude Code