Skip to content

perf(id/app-manifest): avoid quadratic route collision scans #8975

Closed

Description

@dezren39

Evidence

On origin/main (6741fc50a4), pkgs/id/src/app_manifest.rs:381-445 validates each web app's route and optional socket by repeatedly scanning every previously registered app with discovery.apps.iter().find(...). With N valid web apps whose paths are all distinct, all four scans miss for each new app, so discovery performs Θ(N²) route/socket comparisons. commands::serve calls discover_apps during startup (pkgs/id/src/commands/serve.rs:1451), making this cost part of serving startup when an installation has many local apps.

The current contract intentionally rejects duplicate routes and cross-kind route/socket collisions (#6454); this is a performance gap in implementing that contract, not a request to change its semantics.

Why it matters

Adding apps increases discovery work quadratically. A large but valid local app set can make id serve startup disproportionately slow, and the current repeated scans make future growth harder to reason about.

Acceptance criteria

  • Keep route uniqueness, socket uniqueness, and route↔socket collision behavior (including the existing first-conflict diagnostics) unchanged.
  • Track already-registered route and socket values in lookup structures so each app's collision checks are expected O(1), rather than rescanning all registered apps; preserve the conflicting app identity/path needed by errors.
  • Add/adjust tests covering duplicate routes, duplicate sockets, and both cross-kind collision directions, with an oracle that checks the same winning app and rejection/error behavior as today.
  • Add a non-timing-based structural or benchmark check demonstrating discovery no longer performs a full prior-app scan per new app; avoid flaky wall-clock thresholds.
  • Run the focused pkgs/id app-manifest tests and relevant formatting/checks.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Nov 12, 2026
  2. developing-today commented on Nov 12, 2026

    @developing-today
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus/blockedQueue or user escalation statestatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions