Comfy-Org / Comfy-Org/ComfyUI_frontend
perf: guard redundant _addSubgraphInputListeners rebind in input-added handler (SubgraphNode)
- Dominant language
- TypeScript
- Stars
- 2k
- Forks
- 699
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 490
Description
## Summary
In `src/lib/litegraph/src/subgraph/SubgraphNode.ts`, the `input-added` event handler currently calls `_addSubgraphInputListeners` unconditionally whenever an existing input is found — whether by `===` identity or by `id`-based fallback. When the `===` path succeeds the reference hasn't changed, so the abort-and-rebind cycle is safe but unnecessary overhead.
## Suggested change
Add an identity guard so the rebind only runs when it is actually needed (i.e. the id-based fallback path):
```typescript
if (existingInput._subgraphSlot !== subgraphInput) {
this._addSubgraphInputListeners(subgraphInput, existingInput)
}
```
## Context
- Introduced in PR #10187 (fix: prevent nested SubgraphNode input slots from doubling on reload)
- Review comment: https://github.com/Comfy-Org/ComfyUI_frontend/pull/10187#discussion_r2947987074
- Requested by: @christian-byrne
## Notes
Non-blocking optimisation; existing behavior is correct. The guard avoids an unnecessary `AbortController` teardown + re-registration on every `input-added` event that hits the identity-match path.
┆Issue is synchronized with this [Notion page](https://www.notion.so/Issue-10192-perf-guard-redundant-_addSubgraphInputListeners-rebind-in-input-added-handler-Subgr-3266d73d36508106862afb925470ceff) by [Unito](https://www.unito.io)
Contributor guide
Assessment
This issue has not been assessed yet.