-
-
Notifications
You must be signed in to change notification settings - Fork 638
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
make pants help-all
more deterministic
#20764
Conversation
cb9eca5
to
0963895
Compare
for api_type in sorted(all_types, key=attrgetter("__name__")) | ||
} | ||
) | ||
def merge_type_info(this: PluginAPITypeInfo, that: PluginAPITypeInfo) -> PluginAPITypeInfo: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better place we could put this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to be with PluginAPITypeInfo
use of |
0963895
to
771510c
Compare
also converting the lazy dict to a dict (although mostly necessary) does mean that the whole structure needs to be computed for any help. I think it should be possible to restore the laziness, either by making the whole element lazy or by making the items be lazy aggregations. |
b0cf01d
to
b469bad
Compare
it's lazy again! not being lazy caused a measureable performance degradation and fixing it wasn't that hard. |
9234c89
to
74d20cb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking this on!
I've got some general concerns about how we track/register backend types, but that's not for this PR to fix..
names_to_types: dict[str, list[type]] = defaultdict(list) | ||
for api_type in sorted(all_types, key=attrgetter("__qualname__")): | ||
names_to_types[PluginAPITypeInfo.fully_qualified_name_from_type(api_type)].append( | ||
api_type | ||
) | ||
|
||
infos: dict[str, Callable[[], PluginAPITypeInfo]] = { | ||
k: get_api_type_info(v) for k, v in names_to_types.items() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be written using a groupby
:
names_to_types: dict[str, list[type]] = defaultdict(list) | |
for api_type in sorted(all_types, key=attrgetter("__qualname__")): | |
names_to_types[PluginAPITypeInfo.fully_qualified_name_from_type(api_type)].append( | |
api_type | |
) | |
infos: dict[str, Callable[[], PluginAPITypeInfo]] = { | |
k: get_api_type_info(v) for k, v in names_to_types.items() | |
} | |
api_type_name=PluginAPITypeInfo.fully_qualified_name_from_type | |
all_types_sorted=sorted(all_types, key=api_type_name) | |
infos: dict[str, Callable[[], PluginAPITypeInfo]] = { | |
k: get_api_type_info(tuple(v)) | |
for k, v in itertools.groupby(all_types_sorted, key=api_type_name) | |
} |
@@ -322,7 +323,7 @@ class PluginAPITypeInfo: | |||
name: str | |||
module: str | |||
documentation: str | None | |||
provider: str | |||
provider: tuple[str, ...] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not backwards compatible, which is a nuance. Probably not used extensively by end users, but we consume it for docs generation, so need to adapt there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed you have a checked box for this affecting docs.. so 🤷🏽 guess I'm off base here 😬
74d20cb
to
f202d05
Compare
minimises most diff changes
prevents some generated classes from conflicting on name
not being lazy caused a measureable slowdown (1.022 s ± 0.054 s -> 3.184 s ± 0.071 s) in unrelated help goals (`pants help backends`) turning it lazy basically negates that (1.037 s ± 0.090 s) more performance gains could be realised by converting from attributes which are lazy but eagerly materialised to properties which are lazily materialised. That would require more rework
Creating a lambda in the dictcomp means that the lambda captured a reference to the iterator, not the value it contained at that time. Every call to the distinct lambdas would reference the last value processed.
f202d05
to
5ffe11b
Compare
5ffe11b
to
dbf90d1
Compare
pants help-all
is nondeterministic (see #20621 ) . This fixes all sources of nondeterminism I could find:__name__
used instead of__qualname__
, resulting in collisions for classes generated bydistinct_union_per_subclass
OptionField.__qualname__
not mangled__qualname__.GenerateWrapSourceSourcesRequest
not mangledI've also checked:
__qualname__
hasn't broken docsname_to_api_type_info.[].provider
hasn't broken docsname_to_api_type_info
uses__qualname__
consistently