Skip to content

Collect expansion analysis tables in hashes and sort them once at the end#842

Draft
jackfirth wants to merge 1 commit into
masterfrom
perf/analysis-hash-tables
Draft

Collect expansion analysis tables in hashes and sort them once at the end#842
jackfirth wants to merge 1 commit into
masterfrom
perf/analysis-hash-tables

Conversation

@jackfirth

@jackfirth jackfirth commented Jul 22, 2026

Copy link
Copy Markdown
Owner

source-analyze accumulated visited and context syntax objects in mutable sorted maps keyed by syntax path. Expansion writes to those tables far more often than anything reads from them — every visit event records the visited form plus every original subform inside it, and expansion visits nested forms repeatedly — so the same paths get written over and over, each write running syntax-path<=> a logarithmic number of times. Red-black tree lookups came out as the single largest cost in analysis.

Only two places need sorted order, and both run after expansion finishes, so the tables can be plain hashes that get sorted once at the end. This takes analysis of xrepl-lib/xrepl/xrepl.rkt (1877 lines) from ~71s to ~45s. raco test -p resyntax passes.

This overlaps with #840 — both attack the cost of syntax-path<=>, so their speedups don't add. Together they come to ~36s.

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 → ~44s; 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.

… end

`source-analyze` accumulated visited and context syntax objects in mutable
sorted maps keyed by syntax path. Expansion writes to those tables far more
often than anything reads from them: every observed visit event records the
visited form plus every original subform within it, and expansion visits nested
forms repeatedly, so the same paths get written many times over. Each write ran
`syntax-path<=>` a logarithmic number of times, which made red-black tree
lookups the single largest cost in analysis.

Only two places need the tables in sorted order, and both run after expansion
has finished, so the tables can be plain hashes that get sorted once at the end.
This cuts analysis time for `xrepl-lib/xrepl/xrepl.rkt` (1877 lines) from ~78
seconds to ~44 seconds.

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.588%perf/analysis-hash-tables 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