Skip to content
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

Cache the query result. #5112

Merged
merged 4 commits into from
Mar 3, 2018
Merged

Cache the query result. #5112

merged 4 commits into from
Mar 3, 2018

Conversation

Eh2406
Copy link
Contributor

@Eh2406 Eh2406 commented Mar 2, 2018

Small performance gain.

In a test on #4810 (comment)
Before we got to 1700000 ticks in ~97 sec
After we got to 1700000 ticks in ~92 sec. I just reran and got ~82, so it seems to be unstable.
And query disappears from the flame graph

In a test on rust-lang#4810 (comment)
Before we got to 1700000 ticks in ~97 sec
After we got to 1700000 ticks in ~92 sec
And query disappears from the flame graph
@rust-highfive
Copy link

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member

alexcrichton commented Mar 2, 2018

Thanks! Upon seeing this though I wonder if we could perhaps do something like:

struct CachingRegistry<'a> {
    inner: &'a mut Registry + 'a,
    cache: HashMap<...>,
}

impl<'a> CachingRegistry<'a> {
    fn query(&mut self, ...) -> ... {
        // ...
    }
}

and then pass that around instead of &mut Registry?

@Eh2406
Copy link
Contributor Author

Eh2406 commented Mar 3, 2018

That would be cleaner. But would CachingRegistry inpl Registry? Becues Registry.query takes a &mut FnMut(Summary) as its second arg so I don't see how to cache that. Also I'd guess that allocating all the vecs is not free. I like that this caches that. (This is a hunch Not backed by a detailed look at the profile results.)

Mabe all the Context can gane a shared attribute registry_cach of type Rc<RefCell<BTreeMap<Dependency, Rc<Vec<Candidate>>>>>?

We will need a cleaner strategy, looks like multiple test are run on the same thread.

@alexcrichton
Copy link
Member

Oh for sure yeah it can't implement Registry, but I don't think it needs to b/c it doesn't escape resolution?

@Eh2406
Copy link
Contributor Author

Eh2406 commented Mar 3, 2018

Ok I will play with that tomorrow. :-)

@Eh2406
Copy link
Contributor Author

Eh2406 commented Mar 3, 2018

Dose that look better?

@alexcrichton
Copy link
Member

Nice! As one final thing, is the BTreeMap required here or would HashMap work?

@Eh2406
Copy link
Contributor Author

Eh2406 commented Mar 3, 2018

I had gotten the impression that impl hash was not possible for dep. Now I don't know why. It is fixed.

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Collaborator

bors commented Mar 3, 2018

📌 Commit cb0df8e has been approved by alexcrichton

@bors
Copy link
Collaborator

bors commented Mar 3, 2018

⌛ Testing commit cb0df8e with merge adadfab...

bors added a commit that referenced this pull request Mar 3, 2018
Cache the query result.

Small performance gain.

In a test on #4810 (comment)
Before we got to 1700000 ticks in ~97 sec
After we got to 1700000 ticks in ~92 sec. I just reran and got ~82, so it seems to be unstable.
And query disappears from the flame graph
@bors
Copy link
Collaborator

bors commented Mar 3, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing adadfab to master...

@bors bors merged commit cb0df8e into rust-lang:master Mar 3, 2018
@Eh2406 Eh2406 deleted the cache_queries branch March 3, 2018 22:25
@Eh2406 Eh2406 mentioned this pull request Apr 15, 2019
bors added a commit that referenced this pull request Apr 26, 2019
Caching the dependencies

There are 2 sources of facts for the resolver:
1. The `Registry` tells us for a Dependency what versions are available to fulfil it.
2. The `Summary` tells us for a version (and features) what dependencies need to be fulfilled for it to be activated.

The `Registry` was cached with a `RegistryQueryer` back in #5112. This adds a `DepsCache` to cache the calculation of which dependencies are activated by features.

In the happy path `flag_activated` means that we don't get to reuse `build_deps`, but the more we backtrack the more time we save. In pathological cases like #6258 (comment), I have measured this as a 10% improvement with release.

This also means that `build_deps` can be run in a context free way, which may be useful in a follow up PR to solve #6258 (comment).
@ehuss ehuss added this to the 1.26.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants