-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
incr.comp.: Maybe optimize case of dependency-less anonymous queries. #45408
Comments
The current plan is to implement this optimization via not instantiating anonymous nodes at all. Instead their edges should be duplicated to readers. |
I'm a fan of not instantiating anonymous nodes at all. I think that simplifies the overall model and may be a perf win to boot. Seems good. |
Is this still relevant? If yes, could you explain what you mean by "not instantiating anonymous nodes"? |
I think it's still relevant, but I'd have to dig more into the code to be sure. An "anonymous node" is a node in the dependency graph that doesn't correspond to a query. They primarily occur in trait selection, if I recall. |
The query system has changed quite a bit since the last time I looked but I will try to leave some notes in case this is helpful:
|
I'm far from an expert in this area, but I wanted to note some potential wrinkles. As I understand it, anonymous nodes provide two things, which we probably want to preserve:
Finally, I want to note that this may not actually be an optimization. If we copy B's dependencies into things that depend on B, this could actually result in more storage being used, depending on the queries involved. Multiple queries can depend on B. If B depends on 10 queries, now we've replaced each dependency on B with 10 dependencies. In a way, anonymous nodes are an optimization for this case. They deduplicate a set of common edges. |
@tgnottingham's analysis is pretty spot on, afaict. To give some context (which is unfortunately lacking in the issue description): Anonymous dep-nodes were conceived in order to represent things in the dep-graph for which we don't have a query key. In particular we used them for things cached internally in the trait selection system. Their main purpose is to enable dependency tracking for things that don't fit in the query system -- and I think we always considered them as a kind of crutch that we wanted to get rid of as soon as possible. Some time later we discovered that we could use them as a performance optimization for queries that don't get cached on disk, like This issue talks about handling dependency tracking differently: Instead of introducing an anonymous node and pointing the dep-edge to it, we just duplicate the anonymous node's outgoing edges. E.g. A <-------+ +------ C
| |
| v
(anon)
| ^
| |
B <-------+ +------ D becomes A <---------------- C
^ |
| |
+-----------+ |
| |
+---------- | ------+
| |
v |
B <---------D That way, we would still keep all dependencies intact. However, as @tgnottingham points out, this might not actually be an optimization. The number of edges becomes I'm wondering if we could omit allocating anon dep-nodes IFF they have zero outgoing edges? I'm not sure if that could lead to complications. Probably yes. |
Avoid creating anonymous nodes with zero or one dependency. Anonymous nodes are only useful to encode dependencies, and cannot be replayed from one compilation session to another. As such, anonymous nodes without dependency are always green. Anonymous nodes with only one dependency are equivalent to this dependency. cc rust-lang#45408 cc `@michaelwoerister`
Marking as fixed by #85337. |
Some kinds of queries can end up with no dependencies. That is a valid case if their computation solely depends on their query key and not on anything in the environment.
erase_regions_ty
is such a case.We could optimize this case by not allocating a
DepNode
for such query invocations, which in turn would also save registering reads of thatDepNode
.@nikomatsakis, should we do this? If so, I could write some mentoring instructions.
The text was updated successfully, but these errors were encountered: