Traverse syntax eagerly in syntax-search-everything#843
Draft
jackfirth wants to merge 1 commit into
Draft
Conversation
`syntax-search-everything` built a lazy stream, layering `stream-lazy`, `stream-append` and a generated `syntax-parse` search class over every node. None of its three callers benefit much from laziness — two consume the whole traversal — and it runs on every syntax object the expander visits, so the stream machinery costs considerably more than the list it avoids allocating. Building the list directly cuts analysis time for `xrepl-lib/xrepl/xrepl.rkt` (1877 lines) from ~78 seconds to ~74 seconds. The traversal still matches subforms with the same `syntax-parse` patterns `syntax-search` uses, so it walks improper lists and non-list syntax exactly as before. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Resyntax analyzed 1 file in this pull request and found no issues.
Contributor
|
Docs preview: https://resyntax.notjack.space/preview/843/ |
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.
syntax-search-everythingbuilds a lazy stream, layeringstream-lazy,stream-appendand a generatedsyntax-parsesearch class over every node. It runs on every syntax object the expander visits, and two of its three callers consume the whole traversal, so the suspension machinery costs far more than the list it avoids allocating.Building the list directly makes the traversal itself 3–5x faster at every input size, measured in isolation over all 9,262 subforms of
xrepl.rkt, grouped by node count:I can't resolve the end-to-end effect above noise, and I'd rather say so than quote a number. Analysing
xrepl.rktmeasures ~67-69s on this branch against ~71-72s on master, but master itself has ranged 67.9-72.0s across this session on identical code. Interleaved A/B pairs favoured this branch both times, but the effect and the noise are the same order of magnitude. An earlier version of this description claimed ~78s → ~74s; that was a single hot-machine reading and I don't stand behind it.I also tried a generator instead of a list (third column). It's much better than the lazy stream and keeps O(1) early exit, but it's ~1.6x slower than the list everywhere and roughly a wash with the stream on tiny forms — which are 75% of the calls — so it showed no end-to-end benefit.
One open question worth your call:
syntax-completely-original?insyntax-replacement.rktusesfor/and, which short-circuits on the first non-original subform. Going eager removes that early exit, and I haven't measured how often it fires. If it fires often on large syntax, a generator would be the better trade there even though it's worse for the hotanalysis.rktcaller.raco test -p resyntaxpasses. Given the unresolved end-to-end picture, this one is much weaker than #840/#842 and I won't be offended if it's not worth the churn.