rust-analyzer/crates
bors[bot] fc57358efd
Merge #4133
4133: main: eagerly prime goto-definition caches r=matklad a=BurntSushi

This commit eagerly primes the caches used by goto-definition by
submitting a "phantom" goto-definition request. This is perhaps a bit
circuitous, but it does actually get the job done. The result of this
change is that once RA is finished its initial loading of a project,
goto-definition requests are instant. There don't appear to be any more
surprise latency spikes.

This _partially_ addresses #1650 in that it front-loads the latency of the
first goto-definition request, which in turn makes it more predictable and
less surprising. In particular, this addresses the use case where one opens
the text editor, starts reading code for a while, and only later issues the
first goto-definition request. Before this PR, that first goto-definition request
is guaranteed to have high latency in any reasonably sized project. But
after this PR, there's a good chance that it will now be instant.

What this _doesn't_ address is that initial loading time. In fact, it makes it
longer by adding a phantom goto-definition request to the initial startup
sequence. However, I observed that while this did make initial loading
slower, it was overall a somewhat small (but not insignificant) fraction
of initial loading time.

-----

At least, the above is what I _want_ to do. The actual change in this PR is just a proof-of-concept. I came up with after an evening of printf-debugging. Once I found the spot where this cache priming should go, I was unsure of how to generate a phantom input. So I just took an input I knew worked from my printf-debugging and hacked it in. Obviously, what I'd like to do is make this more general such that it will always work.

I don't know whether this is the "right" approach or not. My guess is that there is perhaps a cleaner solution that more directly primes whatever cache is being lazily populated rather than fudging the issue with a phantom goto-definition request.

I created this as a draft PR because I'd really like help making this general. I think whether y'all want to accept this patch is perhaps a separate question. IMO, it seems like a good idea, but to be honest, I'm happy to maintain this patch on my own since it's so trivial. But I would like to generalize it so that it will work in any project.

My thinking is that all I really need to do is find a file and a token somewhere in the loaded project, and then use that as input. But I don't quite know how to connect all the data structures to do that. Any help would be appreciated!

cc @matklad since I've been a worm in your ear about this problem. :-)

Co-authored-by: Andrew Gallant <jamslam@gmail.com>
2020-04-25 14:30:10 +00:00
..
ra_arena Use resize_with 2020-03-31 09:02:12 -04:00
ra_assists Switch to TryFrom 2020-04-25 11:59:18 +02:00
ra_cfg Update versions 2020-02-18 16:12:40 +02:00
ra_db Convert code to text-size 2020-04-25 11:59:18 +02:00
ra_flycheck insta 0.16 2020-04-14 13:57:02 -04:00
ra_fmt Provide more complete AST accessors to support usage in rustc 2020-04-09 11:50:37 +02:00
ra_hir Rename StructField -> Field 2020-04-25 14:23:34 +02:00
ra_hir_def Rename StructField -> Field 2020-04-25 14:23:34 +02:00
ra_hir_expand Merge #4125 2020-04-25 10:35:14 +00:00
ra_hir_ty Rename StructField -> Field 2020-04-25 14:23:34 +02:00
ra_ide Merge #4133 2020-04-25 14:30:10 +00:00
ra_ide_db Rename StructField -> Field 2020-04-25 14:23:34 +02:00
ra_mbe Merge #4134 2020-04-25 10:53:40 +00:00
ra_parser Align grammar for record patterns and literals 2020-04-12 00:00:15 +02:00
ra_proc_macro proc_macro: add ability to log to stderr and view output in vscode 2020-04-23 01:57:02 +03:00
ra_proc_macro_srv Refactor a bit 2020-04-24 09:27:37 +08:00
ra_prof Move timeit to stdx 2020-04-10 20:46:42 +02:00
ra_project_model Merge #4125 2020-04-25 10:35:14 +00:00
ra_syntax Merge #4134 2020-04-25 10:53:40 +00:00
ra_text_edit text-size 1.0.0 2020-04-25 12:15:32 +02:00
ra_tt Improve tt::Subtree debug print 2020-04-10 00:17:32 +08:00
rust-analyzer Merge #4133 2020-04-25 14:30:10 +00:00
stdx Move timeit to stdx 2020-04-10 20:46:42 +02:00
test_utils text-size 1.0.0 2020-04-25 12:15:32 +02:00