Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

graph_engine Benchmarks

The graph engine stores nodes and edges as tensors, using adjacency lists for neighbor lookups.

Node Creation

CountTimePer Node
100107us1.07us
1,0001.67ms1.67us
5,0009.4ms1.88us

Edge Creation (1,000 edges)

TypeTimePer Edge
Directed2.4ms2.4us
Undirected3.6ms3.6us

Neighbor Lookup (star graph)

Fan-outTimePer Neighbor
1016us1.6us
5079us1.6us
100178us1.8us

BFS Traversal (binary tree)

DepthNodesTimePer Node
531110us3.5us
7127442us3.5us
95111.5ms2.9us

Shortest Path (BFS)

Graph TypeSizeTime
Chain10 nodes8.2us
Chain50 nodes44us
Chain100 nodes96us
Grid5x555us
Grid10x10265us

Analysis

  • Undirected edges: ~50% slower than directed (stores reverse edge internally)
  • Traversal: Consistent ~3us per node visited, good BFS implementation
  • Path finding: Near-linear with path length in chains; grid explores more nodes
  • Parallel delete_node: Uses rayon for high-degree nodes (>100 edges)
  • Memory overhead: Each node/edge is a full TensorData (~5-10 allocations)

Storage Model

graph_engine stores each node and edge as a separate tensor:

node:{id} -> TensorData { label, properties... }
edge:{id} -> TensorData { from, to, label, directed, properties... }
adj:{node_id}:out -> TensorData { edge_ids: [...] }
adj:{node_id}:in -> TensorData { edge_ids: [...] }

Trade-offs

  • Pro: Flexible property storage, consistent with tensor model
  • Con: More key lookups than traditional adjacency list
  • Pro: Each component independently updatable

Complexity

OperationTime ComplexityNotes
create_nodeO(1)Hash insert
create_edgeO(1)Hash insert + adjacency update
get_neighborsO(degree)Adjacency list lookup
bfsO(V + E)Standard BFS
shortest_pathO(V + E)BFS-based
delete_nodeO(degree)Removes all edges