Give graph traversal a compact visited set

An exact bitset and reusable frontiers drove the largest improvement in a deep Nyxus graph traversal. Across three measured rounds the operation fell from 149.46 million to 11.11 million instructions.

Represent visited vertices with bits

A breadth-first graph walk checks whether it has seen a vertex every time it follows an edge. Once the graph has dense vertex indices, that check can use one exact bit per vertex. The graph walker also reuses buffers for the current and next level. Together these changes make the inner loop much cheaper while preserving the exact set of reachable vertices.

Measure each change on a populated graph

The benchmark filled each graph with 10,000 vertices and 100,000 edges. It used sparse, hub-heavy and deep-path shapes, validated results against independent reference implementations, and ran each operation eight times per build. On a deep search with a 10,000-hop limit, the baseline averaged 149.46 million complete instructions. Sorted adjacency brought it to 148.68 million, the bitset and reused frontiers to 16.39 million, and the final round with grouped mutations and sorted-buffer reservation to 11.11 million. That is a 92.56% reduction against the baseline.

Look separately at traversal and mutation

The paired trace from the bitset round attributed most of the savings to charged Wasm instructions, with heap fees accounting for 1.15% of the paired reduction. Across the full sequence, the measured deep-impact call touched 46 distinct aligned 64 KiB regions, down from 95. The final mixed-edge workload on the hub graph cost 16.01% more than the preceding round and still came in 48.67% below the baseline. Separate operation and topology results make it possible to decide which improvements suit a particular app.

Code, tests, and related material