-
-
Notifications
You must be signed in to change notification settings - Fork 646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize Pants's data structures by not sorting as much (FrozenOrderedSet
and FrozenDict
)
#14719
Comments
I've started to look into this one. Am I wrong thinking that
|
🎉
Not at all wrong. That's I think what we should do.
Hm I don't remember why we did this. I think so that we can sort dataclasses that compose FrozenDicts. But maybe that's not necessary? I'd recommend:
|
…lementation (pantsbuild#15121) Closes pantsbuild#15111. This is a particular edge case when the same python module has multiple entries, and those entries come from the same target. The better fix is pantsbuild#14719. [ci skip-rust] [ci skip-build-wheels]
…lementation (pantsbuild#15121) Closes pantsbuild#15111. This is a particular edge case when the same python module has multiple entries, and those entries come from the same target. The better fix is pantsbuild#14719. [ci skip-rust] [ci skip-build-wheels]
Thinking more about this...order should probably matter for Ordering should not matter for |
Maybe? See #14195 (comment) re: If something needs to iterate over a set, it should use |
As the author of both
FrozenDict
andFrozenOrderedSet
, I think I was misguided in thinking that deterministic ordering actually matters for the engine. Per #14715 (comment), I believe that all we need is a deterministic__eq__
and__hash__
- the underlying ordering of the elements should be irrelevant and abstracted from the engine.The only place I think ordering should matter is things like error messages, if we want to alphabetize for example. But we can call
sorted()
at the callsites.--
Because both
FrozenDict
andFrozenOrderedSet
consider the order of elements in their__eq__
, we have to eagerly callsort
in lots of places, which is wasted computation. For example:pants/src/python/pants/backend/python/dependency_inference/module_mapper.py
Lines 136 to 139 in 94921a8
We must still use
FrozenDict
rather thandict
so that it's hashable, but I don't think we need to care anymore about ordering.I wonder if we even need
OrderedSet
andFrozenOrderedSet
...can we useset
andfrozenset
? Even if we keep those classes, can we stop using them use much and do the simpler + faster thing of stdlib?--
To implement this change, I recommend:
__eq__
implementations forFrozenDict
and{Frozen,}OrderedSet
sorted()
and the class propertysort_input
, remove when possible.The text was updated successfully, but these errors were encountered: