Skip to content

Grow the territory tree in linear time for thousands of sibling folders #82

Open

Description

@typeweaver

Problem

Growing the territory tree takes longer than linear time when a directory has thousands of sibling folders. On generated repositories of N sibling modules, each with three source files and a placed test, N = 4000 takes about 5 s and N = 8000 about 28 s.

The bucket chain is the cause. When a directory has more than 8 children, 7 open and the rest wait in a "smaller folders" bucket; every split of that bucket opens 7 more and leaves a smaller bucket. N siblings therefore take about N/7 successive splits, and each split re-plans the remaining bucket, so the total work grows quadratically (rankSplits in packages/engine/src/territories/grow-tree.ts, openKids in open-kids.ts).

This predates the territory fixes; it is the remaining super-linear path in territory building.

Proposal

Cut a bucket into groups of 7 in one pass instead of chaining, or cap the chain and let the last bucket stay whole. Sort and weigh the siblings once per directory, and keep the per-folder heat and change counts so a re-plan does not recompute them.

Done when

  • A generated repository of 8000 sibling modules builds its territories in under 5 s.
  • The existing territory tests still pass.
  • A scaling test guards the bound.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions