Skip to content

fix(runtime): zrt_listdir sorts once, after the read - #365

Merged
cmj0121 merged 2 commits into
mainfrom
fix/361-listdir-sort
Oct 14, 2026
Merged

cmj0121 merged 2 commits into
mainfrom
fix/361-listdir-sort

Conversation

@cmj0121

@cmj0121 cmj0121 commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Closes #361.

What

zrt_listdir collects the names and sorts them once with qsort / strcmp, instead of inserting each one into
its place as readdir answers it. Same order as before, so nothing that reads the answer moves (fixpoint
green). Listing 30,000 entries goes from 14.9 s to 0.44 s.

The issue's second point

The language server climbing through every ancestor of a buffer whose project holds no source is filed on its own
as #364. With this change that climb no longer fails: make lsp passes on this machine with 42,516 entries in
$TMPDIR, where it failed before.

Verified

  • TestListdirScales in the runtime suite: 30,000 entries written out of order, checked to come back in strcmp
    order, under a 2 s wall-clock floor. Red on the old sort (14.9 s), green on the new (0.44 s).
  • make lsp locally, against the crowded $TMPDIR: green.
  • Local gates, one at a time, each read: build fixpoint lint fmt-self seed-gaps refuse reject mem-check oracle
    corpus sanitize-corpus mem-peak examples docs-mirror docs-links docs-zerg docs-refused docs-repeat
    marker-codes chapter-codes deviation-check refusal-cites method-gaps gates treesitter dead-code stdlib-test
    compiler-test check-equal reject-fuzz fmt-corpus behaviour conformance productions suites desugar.
  • error-codes-check failed once in that run, naming E3084 as unlisted though it is listed in both places,
    and passed when run again alone with nothing changed. This change touches no code or catalogue; noted in case it
    recurs.

Not verified

  • make test as one board was not run.

🤖 Generated with Claude Code

https://claude.ai/code/session_01N8jd1oK2orM6diHxhvWhC7

    It inserted each name into its sorted place as readdir answered it, on
    the reading that a directory read is a module's files. A tool also
    lists directories it did not make: the language server climbs through
    the ones above a buffer, `$TMPDIR` among them, and insertion over
    readdir's order is quadratic — forty thousand entries took seconds,
    and `make lsp` failed on a machine whose `$TMPDIR` held that many.

    The names are collected, then sorted by one `qsort` with `strcmp`, so
    the order every caller and the fixpoint read is the one it was.

    Closes #361.
    The suite writes thirty thousand entries in an order that is not
    sorted, lists them through a C driver that checks each name follows
    the one before, and bounds the wall clock at two seconds. Red on the
    insertion sort (14.9 s), green after (0.44 s).
@cmj0121
cmj0121 merged commit a56a081 into main Oct 14, 2026
8 checks passed
@cmj0121
cmj0121 deleted the fix/361-listdir-sort branch October 14, 2026 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zrt_listdir sorts by insertion: a large directory costs its square, and make lsp fails under a crowded $TMPDIR

1 participant