ast: Improve set implementation to memoize groudness
Previously sets were not memoizing the groundness check so each call to `IsGround` would iterate until it found a non-ground term. In the worst-case, this would check the entire set. Because we call `IsGround` as part of the inner-loop of the `topdown.evalTerm#enumerate` code-path for sets, this introduced a cross-product! This commit improves the set implementation to maintain a bit that indicates whether the set is ground. When new elements are added to the set, the bit is set accordingly. This change provides a significant speedup for large sets. name old time/op new time/op delta SetIteration/10-20 28.6µs ± 1% 27.3µs ± 1% -4.65% (p=0.008 n=5+5) SetIteration/100-20 263µs ± 1% 152µs ± 1% -42.20% (p=0.008 n=5+5) SetIteration/1000-20 12.5ms ± 0% 1.4ms ± 1% -88.67% (p=0.008 n=5+5) SetIteration/10000-20 1.12s ± 0% 0.02s ± 1% -98.63% (p=0.008 n=5+5) Signed-off-by: Torin Sandall <torinsandall@gmail.com>
T
Torin Sandall committed
00be8a27cb189f4a732ddbd51546088e2a348493
Parent: afdb035