ModelMergeSimple and all merge nodes are O(N²)
Maintainers usually reply within 1 day
@rsteth is already working on this.
Since Nov 18, 2026.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- backend, performance
Research direction
Start with comfy_extras/nodes_model_merging.py and inspect the listed merge nodes, then read ModelPatcher.add_patches() in comfy/model_patcher.py to understand how it handles a whole patch dictionary. Update the affected merge paths to batch patches, grouping keys by resolved ratio in ModelMergeBlocks. Confirm the patches dictionary retains the same keys and strengths, including per-block ratios.
Written by the indexing model from the issue text.
Description
Summary
Every built-in model merge node calls add_patches() once per weight tensor. ModelPatcher.add_patches() rebuilds the model's entire state dict on every call, so a single merge performs N full state-dict builds where N is the number of tensors in the model. For SDXL this is roughly 1,300 builds per merge, and chaining three models means two merges. Changing a ratio invalidates downstream nodes, so the whole cost is paid again on every tweak.
Code
comfy_extras/nodes_model_merging.py:
def merge(self, model1, model2, ratio):
m = model1.clone()
kp = model2.get_key_patches("diffusion_model.")
for k in kp:
m.add_patches({k: kp[k]}, 1.0 - ratio, ratio)
return (m, )
comfy/model_patcher.py, ModelPatcher.add_patches():
def add_patches(self, patches, strength_patch=1.0, strength_model=1.0):
with self.use_ejected():
p = set()
weights_changed = False
model_sd = self.model.state_dict() # rebuilt on every call
for k in patches:
...
Measured impact
Synthetic module with 2,000 tensors, merge of two patchers:
| Implementation | Time per merge |
|---|---|
Current (one add_patches() per key) |
7.07 s |
| Pass the whole dict in one call | 0.004 s (~1600x faster) |
With real SDXL models this is several seconds of UI freeze per merge, and a two-merge chain (three checkpoints) takes roughly twice that. Experimenting with ratios is effectively unusable.
Affected nodes
ModelMergeSimpleModelSubtract/ModelMergeSubtractModelAdd/ModelMergeAddCLIPMergeSimple,CLIPSubtract,CLIPAddModelMergeBlocksand every model-specific merge that subclasses it
Fix
Pass the whole patch dict to add_patches() in one call:
m.add_patches(kp, 1.0 - ratio, ratio)
For ModelMergeBlocks, group keys by their resolved ratio first, then call add_patches() once per group (normally at most three groups) instead of once per key.
I verified that the resulting patches dict — keys, strengths, and per-block ratios — is identical to the old per-key path.
Environment
Reproduced on upstream master as of 2026-11-18 (also present in the current release). This is not platform-specific.
- Dominant language
- Python
- Stars
- 150k
- Forks
- 17.9k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 181
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Comfy-Org/ComfyUI
-
UnboundLocalError on a dangling symlink in custom_nodesPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Feature
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
[Ascend NPU] Trellis2 shape stage aborts: aten::max.dim has no INT32 kernel (EZ1001)Possibly taken @harmehak0173 claimed this 13 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
ROCm gfx1100: contiguous-k/v SDPA workaround is gfx1151-only, MiniMax H3 sampling 2.2x slower on RX 7900 XTXPossibly taken @TwelveNights claimed this 25 days ago. OpenPotential Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
All issues in Comfy-Org/ComfyUI
Similar issues
-
Test: to_hijri() accepts datetime.datetime and uses only the date partPossibly taken A pull request linked to this issue is open or already merged. Opengood first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
omarelshamy25x/shamy-hijri#63 · 3 comments ·
Maintainers usually reply within 1 day
-
polish
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
521xueweihan/HelloGitHub#4729 ·
-
[Bug]: Score parser reads parts of scientific notation as valid scoresPossibly taken @AshutoshSingh840 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
UKGovernmentBEIS/control-arena#992 ·
Maintainers usually reply within 3 days
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
mvalentsev/awesome-free-ai-coding#70 ·
Maintainers usually reply within 1 day