Skip to content

Improve time complexity of identity node removal - #4625

Merged
TrueDoctor merged 4 commits into
GraphiteEditor:masterfrom
0HyperCube:faster-identity-removal
Sep 30, 2026
Merged

TrueDoctor merged 4 commits into
GraphiteEditor:masterfrom
0HyperCube:faster-identity-removal

Conversation

@0HyperCube

Copy link
Copy Markdown
Contributor

Working towards #4572.

  • Reduce time complexity of remove_passthrough_node from O(n) to O(1) by using the cached list of dependants.
  • Remove some unused fields and methods from OriginalLocation
  • Add a test to ensure the remove_passthrough_node function works properly.
  • Validate that the cached list of dependants is accurate (and fix some instances where it contained deleted node ids).

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review completed against the latest diff

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread node-graph/graph-craft/src/document.rs
Comment thread node-graph/graph-craft/src/document.rs Outdated
Comment thread node-graph/graph-craft/src/document.rs
Comment thread node-graph/graph-craft/src/document.rs Outdated
Comment thread node-graph/graph-craft/src/document.rs
Comment thread node-graph/graph-craft/src/document.rs
@0HyperCube
0HyperCube force-pushed the faster-identity-removal branch 2 times, most recently from 09109a0 to 425f0f5 Compare September 30, 2026 11:30

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 3 files (changes from recent commits).

Confidence score: 3/5

  • In node-graph/graph-craft/src/document.rs, nested pruning can leave a removed edge in a live upstream node’s dependant list, making graph dependency state inconsistent; rebuild the cache after pruning, clearing its buckets before repopulating them.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="node-graph/graph-craft/src/document.rs">

<violation number="1" location="node-graph/graph-craft/src/document.rs:884">
P2: Nested pruning can remove an input from a live network node, but this cleanup leaves the removed edge in the live upstream node’s dependant list. Rebuild the cache after input pruning by clearing the buckets and calling `populate_dependants`, rather than filtering only deleted node IDs.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread node-graph/graph-craft/src/document.rs
// Remove references to nodes that have been deleted
for node in self.nodes.values_mut() {
for dependants in &mut node.original_location.dependants {
dependants.retain(|dependant| !old_nodes.contains_key(dependant));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: Nested pruning can remove an input from a live network node, but this cleanup leaves the removed edge in the live upstream node’s dependant list. Rebuild the cache after input pruning by clearing the buckets and calling populate_dependants, rather than filtering only deleted node IDs.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At node-graph/graph-craft/src/document.rs, line 884:

<comment>Nested pruning can remove an input from a live network node, but this cleanup leaves the removed edge in the live upstream node’s dependant list. Rebuild the cache after input pruning by clearing the buckets and calling `populate_dependants`, rather than filtering only deleted node IDs.</comment>

<file context>
@@ -878,13 +878,12 @@ impl NodeNetwork {
 		for node in self.nodes.values_mut() {
 			for dependants in &mut node.original_location.dependants {
-				dependants.clear();
+				dependants.retain(|dependant| !old_nodes.contains_key(dependant));
 			}
 		}
</file context>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nested pruning can remove an input from a live network node

Hopefully not…

auto-merge was automatically disabled September 30, 2026 12:30

Head branch was pushed to by a user without write access

@0HyperCube
0HyperCube force-pushed the faster-identity-removal branch from 8af99aa to de674d5 Compare September 30, 2026 13:03
@TrueDoctor
TrueDoctor added this pull request to the merge queue Sep 30, 2026
Merged via the queue into GraphiteEditor:master with commit 39158de Sep 30, 2026
11 checks passed
purnasai1807-lgtm added a commit to purnasai1807-lgtm/Graphite that referenced this pull request Oct 2, 2026
Improve time complexity of identity node removal (GraphiteEditor#4625)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants