Skip to content

Lazy-import heavy modules for faster startup#183

Open
oxysoft wants to merge 1 commit into1038lab:mainfrom
oxysoft:lazy-imports
Open

Lazy-import heavy modules for faster startup#183
oxysoft wants to merge 1 commit into1038lab:mainfrom
oxysoft:lazy-imports

Conversation

@oxysoft
Copy link

@oxysoft oxysoft commented Feb 19, 2026

Summary

  • Move groundingdino, transformers, matplotlib, cv2, diffusers, onnxruntime, and scipy imports from module top-level into function bodies
  • This defers loading until actual use — models and processing work unchanged
  • Import time drops from ~15.6s to <0.1s during ComfyUI node registration

Details

ComfyUI imports all custom nodes at startup to discover NODE_CLASS_MAPPINGS. The current top-level imports pull in the entire groundingdino → timm → wandb dependency chain (~12s alone) plus transformers (~3.7s) even before any node is used.

By moving these imports into the methods that actually need them, the node classes register instantly and libraries only load when a user first queues a workflow that uses them.

11 files in py/ modified. No functional changes — just import relocation.

Test plan

  • Verify all node classes still appear in ComfyUI node browser
  • Run each segmentation node type to confirm models load correctly
  • Check startup time with python -X importtime or similar

Move groundingdino, transformers, matplotlib, cv2, diffusers,
onnxruntime, and scipy imports from module top-level into function
bodies. This defers loading until actual use, reducing import time
from ~15.6s to <0.1s during ComfyUI startup.
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.

1 participant

Comments