Rust Glancer 0.5.0: Matching rust-analyzer performance
Uh-oh. That is certainly a title I did not expect to ever write.
If you're not aware, Rust Glancer is an experimental LSP server for Rust that keeps idle RAM under 100mb. It is built on a simple concept: when we work on a project, we need only a small fraction of indexed workspace data at a time. Thus, we can just offload our indexed data to filesystem, load just what we needed to execute the query, and offload it again.
This idea works, and it works well. However, to me it was obvious that it will never match rust-analyzer performance, because... Well, come on. rust-analyzer is in-memory, Rust Glancer is on disk. Memory is faster than disk. Simple, right? Well, (after a significant time spent working on optimizations) turns out that the answer is "it depends".
Now Rust Glancer matches rust-analyzer performance on a range of projects where I measured it, and I believe that it should generally be the base case. Obviously, big claims need proofs, so below I provide benchmarks and explanations of how they were prepared.
Additionally, this release implements a lot of new features, bringing Rust Glancer very close to rust-analyzer in terms of functionality, and resolves basically all the caveats about performance and limitations I had announced in the previous posts. Rust Glancer is now a full fledged Rust LSP that is fast enough to feel real time, without any kind of "but".
Let's start with a short demo. Here's how editing with Rust Glancer looks today. Everything is real time.
Additionally, here's a short video showing the same edits done in Rust Glancer and rust-analyzer side to side:
Both are recorded on macbook pro M4 max / 36gb ram.
If you want to try it out, installing is simple:
- VS Code extension.
- OpenVSX extension (cursor, vscodium, etc).
- Zed: official
Rust Glancerextension update PR is open. - nvim:
nvim-lspconfigconfiguration is available, and mason integration exists. It had a slight issue with release artifact names, update PR is open. - All the other editors: grab the release artifact and follow instructions for your editor to set it up.
And of course, obligatory LLM usage disclaimer.
New features
We'll get to performance and benchmarks in a bit. Let's discuss what was added:
- Unsaved files now get full editor support. Previously dirty buffers had limitations and, for example, newly added trait impls could be not applied to a type until you save. Now each keystroke receives full, proper analysis.
- Proper support for
asyncand.await. Previously it was modelled through a shortcut:.awaitwas considered a syntax sugar and I just used the type ofasync fn. Now futures are properly modeled and participate in type inference, including opaque futures, async blocks and closures, and more. - Reworked declarative macro architecture, which enables much better experience inside macros: completions, hovers, inlay hints all work inside (in some cases, even better than in rust-analyzer). Navigation and reference search is better too.
- Improved type inference for callables (closures stored in variables, function pointers, etc), tuple constructors, argument coercions through
Deref/DerefMut, struct updates, tuple patterns with.., enum variants, and more. - Auto imports now suggested in completions: if the item is out of scope, you can import it directly through completion.
- Better and faster hovers, reference search, completion suggestions (now they're context aware and the most suitable suggestions come first).
- Build script discovery adjusted for rust 1.100 (which comes with a new build dir structure).
- Projects can now be opened from subdirectories.
...and more. Full changelog can be found here
Also, this release had the following external contributions. Thank you!
- #272 - fix: Do not follow symlinked directories in the workspace watcher - by @folknor
- #277 - test: completion tests use short kind in snapshots - by @A4-Tacks
- #278 - chore: remove redundant 'homepage' in manifests - by @A4-Tacks
- #287 - fix: Stack overflow on cyclic dyn impl candidate - by @dzania
Performance and benchmarks
Ugh, and now we're getting to an uncomfortable part. I still feel that I am missing something, because intuitively the math is not mathing.
Again: rust-analyzer is in-memory, Rust Glancer is on disk. Memory is faster than disk. This is the reason why I positioned Rust Glancer as an "intentionally incomplete LSP" and thought that there always be some limitations.
This release was VERY focused on optimizations of all sorts. But the main one was migration to Ajika, a library I introduced in the previous blog post. Basically, a persistent-first version of salsa.
While I was working on this release, I was measuring mostly individual query execution time against rust-analyzer. And it was generally in the same ballpark, in most of the cases. Where rust-analyzer took 1ms, Rust Glancer took 28-30; where rust-analyzer took 80ms, Rust Glancer could take 100. In practice, both felt instant.
However, this approach was still mostly a "feel" apart of a limited comparison. And to be able to say "Rust Glancer matches rust-analyzer performance", I needed better benchmarks. So I built a dedicated stand for that.
Caveat: benchmarking is hard. Comparison benchmarking is even harder. And both LSP implementations do a lot of caching, in slightly different ways. Comparing cold requests doesn't make sense, because most of the time requests are not cold. Comparing warm requests is, well, just a cache retrieval. What do?
The set of comparisons I could come up with is roughly the following:
- Measure time from process staring until the LSP is ready.
- Measure indexing time after a restart.
- Simulate a user scenario: replay a session in which there are normal client-initiated requests (like inlay hints), some typing, some saves, navigation across several files, hovers, etc. Basically, a somewhat realistic representation of how a person could use the LSP. And measure the time it that user spends waiting for queries like hover or completion to appear.
- Do a "synthetic" scenario: send hover -> repeat hover -> inlay hints -> repeat inlay hints.
This way we don't try to work in the "request" domain, we're trying to work in a "logical set of actions" domain. It's still not perfect, but I hope that it's representative enough.
To make the configuration similar, I enable cache priming for rust-analyzer, but disable proc macros (Rust Glancer doesn't support them yet), build script evaluation (Rust Glancer only does it passively, so that it's driven by user), and diagnostics.
I couldn't come up with a better idea on how to compare two LSPs, so if you have suggestions, I'd be happy to discuss. And if you find issues in how measurements are done, please do report it. As I said, I still feel that I screwed up somewhere, so if there is a mistake, it is genuine, and I'd like to fix it.
And even in this scheme, there is a nuance. We start the actual scenarios after the server is ready, and we also measure the time it takes for server to say that it's ready. However, server can start answering queries earlier, and in case of rust-analyzer, a difference can be significant (on Bevy, it's ~3 seconds on my machine). I attempted using "first answer" as a metric instead of "server ready", so that I don't give Rust Glancer an unfair advantage in comparison, but I discovered that if I start editing before the rust-analyzer is ready it can panic sporadically, and also that editing can restart cache priming, making overall results much worse (e.g. ~23 seconds instead of ~11 when running scenario on Bevy). Waiting for LSP to be ready was the most stable option, even if rust-analyzer technically can start answering common queries earlier.
Now, with all these caveats said out loud, here are the benchmarks:
...and immediately we need one more. The "winner" is marked green if the difference is 10% or more, but it's important to understand that it's not exactly an apples-to-apples comparison, because Rust Glancer is still less complete than rust-analyzer.
For completeness, here's also a more low-level comparison that I used during development, it compares Rust Glancer vs rust-analyzer answers using rust-analyzer source code as a target. It works worse as a benchmark tool because it does not really account for query order, cache population, etc, but it also shows completeness of the responses (though again, it's not perfect, because some things are hard to compare and in some places Rust Glancer actually produces more information than rust-analyzer, and it causes score to be lower):
Also, interestingly on Debian cold builds are much slower. I started investigating it, and it seems that it isn't caused by filesystem, but rather by the fact that I use mimalloc without arenas, which for some reason is much slower on Linux. It mostly affects cold indexing, but if that's an issue for someone, it's possible to build Rust Glancer from source with arenas enabled: idle memory will be a bit higher, but cold indexing will be noticeably faster. I'll work on a proper investigation and fix in the next release.
If someone wants to reproduce the results of full benchmark, it can be done from the repo root via just compare-lsp --mode full --pairs 5.
How is it possible
First of all, it's generally case by case basis and it depends on a workspace. So it doesn't seem like there is a magic way to just always be faster. Secondly, a repeat request should be faster for rust-analyzer because it won't have to load anything from the disk. Third, most of what made optimizations possible is caused by Ajika. The rest of this section assumes that Rust Glancer is already reworked to be query-first, and Ajika is sufficiently optimized (I did implement quite a bunch of optimizations there too after previous blog post). Ajika itself is not "always on disk only": loaded results are retained in memory for the query duration, and it supports in-memory session storage which is used for dirty buffers; it acts as an overlay, so only changed data is stored in memory.
Rust Glancer tries to compensate hard for the fact that it might need to load information from disk, thus it implements optimizations that help with that. A lot of indexed data is sharded, for example, impl blocks. Thus, Rust Glancer implements some optimizations that are not present in rust-analyzer. For example, Rust Glancer builds a name index for impl blocks to know which impl might contain a method. So if request needs a method called flush, Rust Glancer can skip blocks that can't provide it. AFAIU, rust-analyzer doesn't have this optimization.
Then, rust-analyzer cache priming seems to be doing more work analyzing sysroot (e.g. std) than Rust Glancer (which doesn't treat sysroot in any special way here). Plus, rust-analyzer models more sysroot crates (Rust Glancer doesn't model compiler_builtins and test).
Next, rust-analyzer builds import maps for sysroot during indexing (and can build for other crates on demand), while Rust Glancer doesn't do it. It builds module summaries to skip irrelevant ones, which shifts some of the search to the moment when we calculate completions.
And as a final example, it seems that rust-analyzer only builds trait impl index (by trait and receiver type) during cache priming, but it does not build an inherent impl index (by receiver type). Instead, for inherent impls it builds one on demand, which can make the first request that requires such an index slower. Rust Glancer builds both during lowering.
These are the reasons I could find while investigating it. So, summarizing the result and why it was somewhat suprising even to me, I guess the main reason for that is that I did not really copy rust-analyzer optimizations mindlessly. After migrating to Ajika, my focus was on minimizing filesystem reads first. I only reached to rust-analyzer when I was out of ideas for optimizing a particular place, and applied applicable optimizations on top of the original idea. Besides, Rust Glancer in some cases leaves more work to be done by query where it helps to reduce initial indexing time.
Fun note
Switching Rust Glancer from manually implemented caches to Ajika resulted not only in increased performance, but also in ability to remove approximately 25000 lines of code. It was not slop, it was code that was reasonable at the time, it's just that wiring caches manually and intersecting them with the application logic stops being efficient at a certain point.

Ajika itself is ~12KLoC including tests, benchmarks, and comments, so it's not moving stuff from one project to another either.
Sometimes finding the right abstraction can help a lot.
What's next
I am very happy with this release. A ton of work and many morning and evening hours went into it.
LLMs certainly help with development, and they can do a lot of heavy lifting, but they still require full focus on the project, because they have really poor judgement, especially in such a vaguely defined domain as LSP development.
During the work on Ajika, the APIs generated by LLM during prototyping phase were... interesting. During the work on Rust Glancer, the LLMs always want to go off rails chasing stuff "but what if several crates with different edition would have a #[path] on module leading to the same file outside of the workspace". And asking LLMs for ideas only goes so far, generally you need to supply your own ideas and measure outcomes, LLMs mostly help with the "middle" part of the implementation process. Which is great help, but still not a free ride. It was still fun, though, which is what matters.
So, this month, given the amount of research, prototyping, features and optimizations, was tough, and I do feel a bit tired. I guess I'll take a break to recover. I mean, I had to postpone Zelda: Ocarina of Time playthrough because of work on this release, and now we've got GTA 6! Gotta chill a bit.
And then, in a few weeks, I plan to finally start working on proc macros. This seems to be the last big feature that is not implemented yet, and after that it will be just a lot of polishing. There is also a fair share of optimizations I want to try, so depending on how it goes, Rust Glancer can become even faster.
Otherwise, thanks for reading. As usual, the best way to support if you like the project is to star the repo (but only if you like it!) and/or follow me on twitter. Ugh, and go check out Ajika if you haven't already.
Stay tuned!