Skip to content

Stop traversing whole subtrees to decide if syntax is one line or many#841

Draft
jackfirth wants to merge 1 commit into
masterfrom
perf/syntax-line-count
Draft

Stop traversing whole subtrees to decide if syntax is one line or many#841
jackfirth wants to merge 1 commit into
masterfrom
perf/syntax-line-count

Conversation

@jackfirth

@jackfirth jackfirth commented Jul 22, 2026

Copy link
Copy Markdown
Owner

oneline-syntax? and multiline-syntax? counted every distinct source line among all the atoms in a syntax object, streaming the whole subtree through a transducer pipeline. Neither caller needs an exact count, and both build the full stream even when the second line turns up immediately.

Counting with a direct traversal that stops at two distinct lines takes analysis of xrepl-lib/xrepl/xrepl.rkt (1877 lines) from ~71s to ~63s.

The new traversal deliberately mirrors syntax-search's shape, including how it handles improper lists and how it treats non-list, non-atom syntax (vectors, say) as having no lines at all. I ran both implementations over every subform of several large source files plus some hand-built edge cases and got identical answers on all 28,585 syntax objects. raco test -p resyntax passes.

Found by profiling, in the same vein as #800.

Measurement note: figures are the minimum of 3 runs after a warmup. An earlier version of this description said ~78s → ~65s; that baseline was taken on a thermally throttled machine and overstated the ratio. Repeated runs on identical code vary by up to ~6% here, so treat differences smaller than that as unresolved.

`oneline-syntax?` and `multiline-syntax?` were implemented by counting every
distinct source line among all the atoms in a syntax object, using a
`syntax-search` stream fed through a rebellion transducer pipeline. Neither
caller needs an exact count, and both build a lazy stream over the entire
subtree even when the second line is found immediately.

Counting directly with a recursive traversal that stops at two distinct lines
cuts analysis time for `xrepl-lib/xrepl/xrepl.rkt` (1877 lines) from ~78 seconds
to ~65 seconds.

The traversal deliberately mirrors `syntax-search`'s shape, including its
handling of improper lists and its treatment of non-list, non-atom syntax (such
as vectors) as having no lines at all. Both implementations were run against
every subform of several large source files, plus hand-built edge cases, with
identical results on all 28,585 syntax objects.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resyntax analyzed 1 file in this pull request and found no issues.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage is 96.59%perf/syntax-line-count into master. No base build found for master.

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.

2 participants