Description
Sam Caldwell built a ~1000 line program in Hackett that takes 25 seconds to expand. I spent some time profiling the expansion process and thought I'd share the results, though I'm not familiar enough with Hackett's implementation to suggest a fix.
Code: https://gist.github.com/michaelballantyne/64c18ec55abd7f1acdc4a41655239b54
Profile: https://gist.github.com/michaelballantyne/05488da82d07c5db9d03866b3c024334
It looks like most of the time (~70%) is spent on this line: https://github.com/lexi-lambda/hackett/blob/master/hackett-lib/hackett/private/typecheck.rkt#L222
when called by apply-subst
.
The size of the type context for this program reaches about 2500 entries, so the linear search by findf
gets pricey, especially with free-identifier=?
involved in the predicate. Perhaps the context could use a free identifier table instead?
I also noticed that τ<:/full!
appliesapply-current-subst
at every type it examines, and that it will then reapply the same substitution when it recurs, resulting in a quadratic number of apply-subst
operations being applied to leaves.