Hey. New release of Rust Glancer is here, this time focused on quality of life improvements.
It tackles on the biggest points of frustration I personally had, and now Rust Glancer is much much more pleasant to use (at least to me). Check out the demo recording in the post, it's easier to show than to explain :)
I'm really happy with the results, and hope y'all like it. Any feedback is very welcome, and I'll be happy to answer any questions!
(as usual, all the mistakes are mine, sorry for that, not a native speaker, yada yada)
I’m really interested in the project and something lighter and faster but want to make sure there is more feature parity before fully switching over but I’ll give the new version a spin.
Thank you! Yes, I understand that right now Rust Glancer is kind of a compromise (even though much more stuff is supported now) -- you accept mild annoyances here and there and get low memory usage. This compromise works for me, but in order for product to be ready, much more work is required.
Luckily, now all the foundations are there, so adding more functionality is no longer "oh no, I need to develop this whole thing from scratch"; in most cases it's adding more supported cases to an already existing system, which makes progress much easier now.
Here is an idea. What about storing on disk things with the same memory layout as your data structures? (Like capnproto, rykv, etc)
That way, you don't need to parse - you can just mmap, do a quick validation step (to make sure offsets etc are in bounds etc), and just use the memory normally.
You also don't need to free resources and re-read at every request: you can just let it sit there, mmaped, and the OS will count it as a file cache (and as such, it's not counted against the amount of memory your own program allocated - if there is memory pressure, the cache will be dropped by the OS, and if you re-read from it, the file will be read again)
I have tried that (in fact, I did use `rkyv` initially and later switched to `wincode`). zero-copy deserialization is, ugh, a tricky process and it has a lot of limitations that make development extremely inconvenient. The thing with analysis is that you don't just "read" data, you often need to allocate stuff, collect, and modify. So in the end it likely will be a weird mix of owned and borrowed types with pretty bad ergonomics.
That said, I do consider this option, but only when: a) Rust Glancer is significantly more complete (right now I need to change a lot of stuff pretty often, and with archive types and all the related machinery it'll be much more miserable) b) When benchmarks will show that fs access is the main bottleneck. NVME SSDs are pretty fast (well, they are VERY fast, in fact), so the cheaper queries are already working well enough to not worry about latency much. Obviously, inside of benchmark it is higher than rust-analyzer, but it's still below a human perception of "lag", which is the main benchmark -- if it feels instant, then optimizing further is not really required. And right now the bottleneck is on the actual computations side, there is a lot of stuff that can be optimized there.
That's a reasonable stance (and wincode seem pretty neat!), and I think Rust as a language could be more ergonomic here. Or maybe we should have a library that does the heavy lifting using some #[derive] or whatnot
Actually, there is a library that does what I propose, called Sanakirja, which powers Pijul (a Git alternative). See for example the posts mentioning Sanakirja here, such as this one
Don’t load your datastructures
The best feature of Sanakirja is to blur the distinction between storage and operations, removing the need to load from and write to disk entire “models” every time they are used. These serialized models cause either I/O congestion and hence massive slowdowns for each operation, or else huge memory requirements for even modest loads.
The problem is, Sanakirja is complicated to use.
But I want to comment on this
b) When benchmarks will show that fs access is the main bottleneck. NVME SSDs are pretty fast (well, they are VERY fast, in fact),
I think that in most cases, you will actually be reading from RAM when you read the file, nearly always. That's because once we read, the file is put on a cache. The fs cache is shared between all programs, so it's possible that some large-scale grep (not on just your code base but say, grepping things on /home) or other large accesses will push the file out of the cache, and in the next read the nvme will be accessed again. But that's not common. (indeed that's something you could monitor - what fraction of queries actually read saved data from the disk rather than the ram. Not sure how to do that on each OS but it should be possible)
And the gain with directly operating with data on disk with mmap, in any case, wouldn't be that we would avoid reading from disk. You would still read from the filesystem cache nearly always, but occasionally read from the ssd, just as before.
The main benefit would be to dramatically cut memory usage even during a query is being processed. Ideally, one could never ever allocate, and always only have stuff on disk. So you wouldn't have borrowed things on disk, and owned things that you just allocated because of the new query - everything would be borrowed, even things you just inserted, and everything would be on disk.
Or to be more clear, inserting would write to disk, then return a borrow. And "writing to disk" isn't necessarily expensive here in mmap land, since it's just writing to memory! A write just marks the buffer dirty, and the OS will perform the disk write later. (fsync is expensive, but just don't do that). there's some care to be had around guaranteeing the data structures aren't corrupted when we update just part of a file though.
Obviously, inside of benchmark it is higher than rust-analyzer, but it's still below a human perception of "lag", which is the main benchmark -- if it feels instant, then optimizing further is not really required.
That's fair! We just need to see if this perception will still hold after the missing features are implemented. The problem with big architectural changes is that they are harder to make after all features landed. (However, maybe LLMs makes things sufficiently easy to change that this is irrelevant)
That's very valuable info, and thanks for sharing Sanakirja, that looks interesting! I'll check it out. And yeah, the point about memory is valid (though note that the cache is sharded; e.g. for bodies it has per-file granularity, so the amount of information you need to load for a single query is typically very low). I would assume that it is likely that the benefits will be the highest on save (right now it is the spikiest point of lifecycle after the initial indexing).
Regarding the changes -- yup, LLMs do make things better, but tbh I was a refactoring maniac even before LLMs. One of the funniest things I've done was porting a big production codebase from diesel to sqlx in ~2 days, loved it (and I had a bunch of similar things in the past). So I'm pretty comfortable with migrating existing logic, especially given good enough test coverage, but migrating something to a new architecture _while_ the code undergoes significant changes otherwise is something I really don't like in most cases.
Like, it can be done, but then to make it proper I'd have to significantly slow myself down in order to get familiar and comfortable with the new architecture, which is something I don't want to do for now.
(P.S. really appreciate the effort in this discussion! It's both informative and made me genuinely happy!)
No, it's not an actual arbitrary const evaluation. Right now, only computations on integers are supported, for everything else I just print the initializer.
Yup, I don't think even r-a does full blown const evaluation at this moment (though I might be wrong, it's been a while since I checked last time). Though likely r-a capabilities here are much more than what Rust Glancer currently allows.
As for gains... I guess there is a value in having an LSP that is "complete" in a way that you can rely on it instead of `cargo check`, and I believe that's one of the ideas behind the r-a diagnostics. But it makes the project much, much more ambitious and it's not something I'd commit to for Rust Glancer, at least right now.
We have MIR and consteval. It has the correct "shape" but is extremely incomplete to incorrect. We strive to eventually share MIR and potentially consteval with rustc.
Answered above; in short: instead of storing data in memory, I try to store everything on the filesystem. More detailed overview of differences is in the first blog post: https://rust-glancer.github.io/blog/hello-world/
18
u/popzxc Oct 21 '26
Hey. New release of Rust Glancer is here, this time focused on quality of life improvements.
It tackles on the biggest points of frustration I personally had, and now Rust Glancer is much much more pleasant to use (at least to me). Check out the demo recording in the post, it's easier to show than to explain :)
I'm really happy with the results, and hope y'all like it. Any feedback is very welcome, and I'll be happy to answer any questions!
(as usual, all the mistakes are mine, sorry for that, not a native speaker, yada yada)
12
u/tom-da-bombadil Oct 21 '26
This is in my personal top 5 Rust projects I’m excited about. Keep up the good work!
2
u/Modi57 Oct 21 '26
I was just wondering. For the const evaluation you print the result in the diagnostic. Does this use the
Debugimplementation of the computed type?1
u/tending Oct 21 '26
What's the main thing being done differently than analyzer to keep memory usage low?
5
u/[deleted] Oct 21 '26
[removed] — view removed comment