Memoize the normalize function#63
Conversation
|
Hmm... definitely doesn't solve all problems (except for the case with exact-repeat terms), but seems like a good improvement. For reference, speeds without this PR on my machine: julia> @time normalize(t, rs)
2.794503 seconds (5.83 M allocations: 298.442 MiB, 3.13% gc time)
@term(0)
julia> @time normalize(t, rs)
0.007747 seconds (121.90 k allocations: 11.674 MiB)
@term(0)
julia> @time normalize(t2, rs)
0.015232 seconds (158.36 k allocations: 15.167 MiB, 37.15% gc time)
@term(1)
julia> @time normalize(t2, rs)
0.018949 seconds (158.36 k allocations: 15.167 MiB, 35.53% gc time)
@term(1) |
|
The real advantage is that repeated sub-terms get memoized. Notice that the time for This would play a big role if you have some big term that you want to normalize and only part of it is changing with each iterated normalization. But yes, this is only part of the speed problem. Dynamic dispatch is the big thing to fix (I think). |
|
@MasonProtter Looking back at this, I'm having second thoughts. Although the goals of this PR and #60 are performance-oriented, it seems like it might make sense to finalize #60 with only minor/specialized optimizations and consider memoization in more detail under a separate PR. Similarly, it seems that we may benefit from being more clever with memoization strategies (e.g. memoizing each rule separately, storing whether or not a rule applies to a broad class of patterns, etc.). For these reasons, would you mind if I revert this PR and open a separate issue to explore memoization in more detail? |
|
Yes, I was thinking about this as well and I agree. |
|
Reverted, with #68 for discussion. :) |
This gives some nice speed improvements for (sub)terms which are normalized many times.
Let me know if I'm doing this PR wrong. I'm targeting your branch
fix/speedinstead of master since I think this falls under PR #60.