-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
2 changed files
with
81 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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