Add INLINABLE to AST traversals — full builds -9%#19
Merged
Conversation
…OnValuesM
Two-line change: add {-# INLINABLE #-} pragmas to the polymorphic
traversal helpers so callers (notably Entailment.replaceTypeClass-
Dictionaries with its WriterT/StateT/TypeCheckM stack) can specialise
the dictionary at use site.
Test suite passes (1340 examples).
Initial measurement (load avg ~4-7, baseline c84101d):
full -9.6% (58.4s -> 52.8s)
nochange +8.4% (0.643s -> 0.697s) -- regression to investigate
prelude -0.5%
leaf -4.3%
Per-round full deltas: -4.0, -10.1, -10.3, -8.7 -- consistent.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
zyla
approved these changes
May 11, 2026
Collaborator
zyla
left a comment
There was a problem hiding this comment.
LG
I was super confused at first when I saw this - my thought was "Wait, didn't we add INLINE to the traversals a long time ago?". The answer is: yes, but to the type traversals, not full AST.
|
Hi! the work you are doing here is very good! Does it make sense to port this to the official one? |
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.
Summary
Two-line change: add
{-# INLINABLE #-}toeverywhereOnValuesTopDownMandeverywhereOnValuesMinsrc/Language/PureScript/AST/Traversals.hs.Why
The hot caller is
Entailment.replaceTypeClassDictionaries(src/Language/PureScript/TypeChecker/Entailment.hs:118-139). It runs once per typechecked declaration with monadm = WriterT (Any, [...]) (StateT InstanceContext TypeCheckM)— four transformer layers, each with its own>>=per recursive descent over Expr trees.The traversal helpers were polymorphic over
Monad m =>. WithoutINLINABLE, GHC can specialise within the defining module but cannot see the unfolding when compiling other modules — so callers go through the runtimeMonaddictionary on every recursive bind. AddingINLINABLEexposes the unfolding in the.hifile; GHC's specialiser at each call site then collapses the polymorphic helper into a flat, monad-specialised loop.Measurements
Two interleaved-measurement runs (
exp run, median-of-4 after warm-up) against the pre-change baseline (c84101d8) on the pr-admin workload (1758 modules):Per-round full deltas (Run 2): −10.1%, −15.2%, −9.6%, −8.9% — even the worst round is −8.9%, so the full-build win is robust. nochange/prelude/leaf are within noise floor (Run 1's nochange +8.4% was a load-contamination artefact on a 643 ms wallclock; Run 2's −3.0% confirms it).
Cost
stack buildtime: unchanged within noise.stack test --fastpasses 1340 examples.Test plan
stack build(optimised) — greenstack test --fast— 1340 examples, 0 failuresexp run --scenarios all --runs 5— robust ~−9% on full builds across two runs🤖 Generated with Claude Code