Commit Graph

6 Commits

Author SHA1 Message Date
Sergey Elantsev 1ad01debf3 tiny optimisations of dag.Set
1. Use hint for map size in Set.Copy().
2. Use Set.Copy() if Set.Difference() argument is empty.
2021-04-09 22:59:30 +03:00
Dennis Gursky 550de86135
Set Intersection #performance (#28183)
* Set Intersection #performance

Intersection is faster for sets of different sizes if one iterates over the shorter set and checks the presence of an element in a larger one. For an edge case consider `s` having 1M entries and `other` no entries at all. In this case original code will iterate over 1M entries in `s` not finding anything and then returning an empty result set. In the patched code the iteration won't happen at all and result is returned immediately.

This change is inspired by profiling a relatively large terraform configuration, where the time to validate was sped up 4x with this change.
2021-03-24 13:04:37 -04:00
James Bardin 8e4bd669e8 test Set.Copy, Graph.UpEdges, Graph.DownEdges 2020-06-11 09:53:09 -04:00
James Bardin 32ae3b5452 make dag.Set a simple map
This allows iteration directly over the set, removing the need to
allocate and copy a new slice for every iteration.
2020-02-19 14:46:35 -05:00
Martin Atkins b28fc1cd20 dag: method for filtering a set on arbitrary criteria 2017-05-11 11:57:46 -07:00
Mitchell Hashimoto 77c445a838
dag: Set difference 2017-02-03 21:18:33 +01:00