Skip to content

Performance: Cache node instances in Runtime worker to avoid repeated instantiation #143

@coderabbitai

Description

@coderabbitai

Issue Description

Currently in the Runtime._worker method, a new node instance is created for each execution:

node = self._node_mapping[state["node_name"]]
outputs = await node()._execute(node.Inputs(**state["inputs"]))

This approach ensures isolation but may impact performance, especially under high throughput scenarios.

Proposed Solution

Consider caching node instances to improve performance:

  • Cache instances in a dictionary keyed by node name
  • Reuse existing instances if nodes are stateless
  • Manage a pool of instances if needed

Implementation Considerations

  • Evaluate if nodes are stateless and safe to reuse
  • Consider thread/async safety implications
  • Measure performance impact before and after changes

References

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthelp wantedExtra attention is needed

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions