Repository navigation
fix(runtime): zrt_listdir sorts once, after the read - #365
Merged
Merged
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #361.
What
zrt_listdircollects the names and sorts them once withqsort/strcmp, instead of inserting each one intoits place as
readdiranswers it. Same order as before, so nothing that reads the answer moves (fixpointgreen). 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 lsppasses on this machine with 42,516 entries in$TMPDIR, where it failed before.Verified
TestListdirScalesin the runtime suite: 30,000 entries written out of order, checked to come back in strcmporder, under a 2 s wall-clock floor. Red on the old sort (14.9 s), green on the new (0.44 s).
make lsplocally, against the crowded$TMPDIR: green.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-checkfailed once in that run, namingE3084as 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 testas one board was not run.🤖 Generated with Claude Code
https://claude.ai/code/session_01N8jd1oK2orM6diHxhvWhC7