Skip to content

GraphType cached derived fields + plain-Python graph-op hot paths - #89

Open
yinoneliraz wants to merge 1 commit into
masterfrom
yinon/graphtype-cached-fields
Open

yinoneliraz wants to merge 1 commit into
masterfrom
yinon/graphtype-cached-fields

Conversation

@yinoneliraz

Copy link
Copy Markdown
Contributor
  • ComputationEdge: cache computed_hash (edges are hashed on every frozenset build/lookup; fields are immutable).
  • GraphType: lazily cached derived fields — nodes, node_to_incoming_edges, node_to_forward_neighbors — plus seed_nodes() so transformations that know the node-set delta (merge_graphs, replace_nodes, replace_source) propagate the cache in O(delta) instead of forcing an O(E) rescan.
  • make_computation_node: memoize by callable, skipping repeated inspect.signature work.
  • replace_source / replace_destination: single-pass plain loops instead of 4 gamla-combinator passes over the edges.
  • merge_graphs, make_first/make_and/make_or, _make_compose_inner, _infer_composition_edges: plain-Python hot paths (kills per-edge curried closures and hidden iscoroutinefunction checks); unbound signature computed once per candidate node using the cached incoming-edges field.
  • duplication: use cached nodes/forward-neighbors fields.

Benchmark (bot-building-shaped workload, 4498 edges, 200 replaces): 3141ms -> 677ms total; replace_source 2534ms -> 289ms. All 102 tests pass; canonical graph shapes identical to master.

- ComputationEdge: cache computed_hash (edges are hashed on every frozenset
  build/lookup; fields are immutable).
- GraphType: lazily cached derived fields — nodes, node_to_incoming_edges,
  node_to_forward_neighbors — plus seed_nodes() so transformations that know
  the node-set delta (merge_graphs, replace_nodes, replace_source) propagate
  the cache in O(delta) instead of forcing an O(E) rescan.
- make_computation_node: memoize by callable, skipping repeated
  inspect.signature work.
- replace_source / replace_destination: single-pass plain loops instead of
  4 gamla-combinator passes over the edges.
- merge_graphs, make_first/make_and/make_or, _make_compose_inner,
  _infer_composition_edges: plain-Python hot paths (kills per-edge curried
  closures and hidden iscoroutinefunction checks); unbound signature computed
  once per candidate node using the cached incoming-edges field.
- duplication: use cached nodes/forward-neighbors fields.

Benchmark (bot-building-shaped workload, 4498 edges, 200 replaces):
3141ms -> 677ms total; replace_source 2534ms -> 289ms. All 102 tests pass;
canonical graph shapes identical to master.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@yinoneliraz
yinoneliraz force-pushed the yinon/graphtype-cached-fields branch from 5ee8c4b to 0b9d8ce Compare July 12, 2026 09:50
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