Memoise mk_prec_matrix - #2063
Conversation
|
Can this be done by having the partial application not become stale for useless updates like defining a constant instead? |
|
I think I'd prefer a world where the matrix is stored in the grammar as an option ref value. If :
then the new grammar's pointer can point to the old matrix. Otherwise, the new grammar either gets a fresh pointer with Subsequently, the If the rest of |
|
@mn200 sorry this one took so long I've updated the PR |
|
Thanks! Do you have a cool new flame graph demonstrating an improvement? |

Hi, I was playing around with some vibe coded profiling/flame graph tools I got Claude to put into my copy of PolyML, and found a few places when building theories that seem pretty straight forward to optimise. The first of them is that building the precedence matrix for the term parser in
mk_prec_matrixshows up a surprising amount in the flame graph.Here,
mk_prec_matrixis in pink and it's showing as 11.4% of the build.So it seems like the precedence matrix is being rebuilt a bit more often than it needs to. In this PR I've memoised it so it only re-computes when grammar rules and "specials" are changed (the only two fields
mk_prec_matrixreads). This is cutting my build time (building kernel, core_theories, and more_theories) from an average of 957s to 876s.After the change the flame graph shows
mk_prec_matrixhaving gone down to 2.1% (still in pink).