rust-lang / rust-lang/rust-analyzer

Consider sharing Semantics caches between requests

Open
#20,003 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-ide A-perf
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

Lots of file wide IDE features will re-populate the Semantics caches all the same, doing a bunch of repeated work due to us creating a new Semantics instance per request. That is kind of wasted as all the data will be the same!

So ideally we would stash away a Arc<Semantics> in GlobalState (or probably Analysis) somewhere, replace the RefCells within with RwLocks and clone the arc into requests on demand. And whenever a db invalidation comes in, we just replace the stored Arc with an Arc::default again to refresh it. This should generally speed up a couple of things I believe. That also means we should be able to cache some more stuff in Semantics that may be re-used between requests that is prone to invalidations.

Now, we can't really stash away Semantics itself as it won't be send due to the database handle within, but we can do the same with its caches directly, that is store Arc<RwLock<SourceToDefCache>> etc...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating Semantics, GlobalState, and Analysis, then trace how requests create Semantics and how database invalidations are handled. Review the existing RefCell-based caches and determine the affected cache types; done means reusable cache state is shared across requests and refreshed when invalidation occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools, performance
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.