Skip to content

[GEN-08] topological_sort() runs O(N) on every SyncRequest, then truncates to 500 #268

@intendednull

Description

@intendednull

Commit: 2f26d91 · Finding: GEN-08

Problem

crates/client/src/listeners.rs:298-307 calls dag.topological_sort() over the entire DAG on every WireMessage::SyncRequest, then takes only the first 500 entries. topological_sort (crates/state/src/dag.rs:316) iterates every event, builds in-degree + dependents maps, and allocates a Vec of size self.events.len().

For a server with 50k events every sync request pays the full sort cost even though only the first 500 are sent. An N+1 amplifier as peers increase. The in-source TODO acknowledges the temporary nature; the worker has a heads-based sync that should be the migration target (see #65, #207).

Distinct from #65 (protocol change) and #207 (500 cap) — this finding is specifically about the wasted work per request.

Fix

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions