Live data from Hacker News

Rust Glancer: Rust LSP using 100x less RAM

rust-glancer.github.io

121–129 of 129 posts

Re: Rust Glancer: Rust LSP using 100x less RAM

#121
post #114

Earlier quoted context omitted.

Could you mind to tell me what is your plan on proc-macros ? You said you have an idea to “will not require actual code execution”. On the other hand, RA current method of handling in Proc-Macros are very fragile.

The exact shape is TBD (I target proc macros support for 0.3.0, whereas 0.2.0 will be about completeness/editors support), but in short -- I'm thinking about "plugin"/DSL architecture where proc macro _effects_ can be described beforehand and applied by the LSP without actual code execution. Executing proc macros is a lot of effort, but LSP mostly cares about the externally observable effects, which is a much smaller…

If it’s possible, that would be awesome. Do you mean that the author of the proc macro provides that information through attributes?

(Disclosure: I originally implemented the proc-macro part of RA.)

Re: Rust Glancer: Rust LSP using 100x less RAM

#122
post #88

Tangential, but I've found something LLMs are actually ridiculously good at is making LSP servers. I couldn't find good TLA+ bindings for Neovim, so I got Claude to hack together an LSP server for it [1]. It works shockingly well, and it only took about an hour of arguing with Claude to do it. I find it's not terribly good at actually writing TLA+ (with some very recent tests with Fable), so I'm not completely useles…

The LSP spec is hideously complicated and has weird edge cases around what exactly is a newline, what content-encoding is used for counting offsets, and timing of events. I'd be very surprised if Claude got those right.

My experience so far says that without subject-matter-expert prompting, Claude will take shortcuts with a naive "\r?\n" regexp etc.

I would happily let Claude write tests for the various newline formats and content-encodings, though.

Re: Rust Glancer: Rust LSP using 100x less RAM

#124
post #20

Earlier quoted context omitted.

Very little quality, let alone high-quality, code is written in VSCode.

You've got to re-evaluate... something if you genuinely believe that. Pretty much the same level of sanity as "very few good films use CGI".

I'd go as far as ask "what is your IDE of choice?" during the interview and rejected candidates that answer VSCode and VSCode clones. Now it doesn't matter because of LLMs though.

Re: Rust Glancer: Rust LSP using 100x less RAM

#126
post #88

Tangential, but I've found something LLMs are actually ridiculously good at is making LSP servers. I couldn't find good TLA+ bindings for Neovim, so I got Claude to hack together an LSP server for it [1]. It works shockingly well, and it only took about an hour of arguing with Claude to do it. I find it's not terribly good at actually writing TLA+ (with some very recent tests with Fable), so I'm not completely useles…

The LSP spec is hideously complicated and has weird edge cases around what exactly is a newline, what content-encoding is used for counting offsets, and timing of events. I'd be very surprised if Claude got those right. My experience so far says that without subject-matter-expert prompting, Claude will take shortcuts with a naive "\r?\n" regexp etc. I would happily let Claude write tests for the various newline forma…

I'm sure there are edge cases for stuff I haven't tested, but I've written many lines of TLA+ with the generated bindings and it seems to work fine as far as I can tell. The model-checker appears to work as expected.

Granted, I suspect part of it is that they are cribbing pretty heavily from the official VSCode TLA+ bindings, so it probably gets a lot for free.

Re: Rust Glancer: Rust LSP using 100x less RAM

#127
post #113
post #111

Earlier quoted context omitted.

Let's say I type "SomeStructure" and haven't imported it, how does rust glancer _not_ end up poking at all the dependencies to figure out where it is, and to import it? In some sense I feel like that example is the canonical "you need a full picture of the world" case, to the point that it's probably worth special casing _just_ that, and using local analysis for everything... but it seems hard to avoid that pain on a…

On the first question -- auto imports is an example of a "heavy" functionality since we indeed need to scan more than is imported in the project, which is why I'm still working on this to optimize properly (it's decently fast, but I want it to be faster before I'll enable it, since it's also something we want to see in completions, and completions must be _very_ fast). Still, we don't need "everything": we only need…

Unfortunately that does not work. Consider:

    // Crate indirect_dep:
    pub struct Foo;
    
    // Crate direct_dep:
    extern crate indirect_dep;
    pub use indirect_dep::*;
    
    // Crate my_crate:
    use direct_dep::$0;
($0 denotes the cursor). You cannot know what to complete without analyzing `indirect_dep`. Add macros to the mix and you're going to get a nightmare (yes, name resolution in Rust is a nightmare).

In fact, you sometimes need to do type inference inside bodies to infer other bodies, because auto traits propagate across opaques. You might say this does not matter because it only matters for diagnostics... But it does not. It can matter for method resolution.

In general, I'm fairly sure that it is just impossible to build a 100% correct analyzer for Rust code without a query system like rustc's (it can be stored on disk, that's a different story). You can go pretty far without - and this will be enough for some people for an IDE! - but not all the way.

Re: Rust Glancer: Rust LSP using 100x less RAM

#128
post #42

Earlier quoted context omitted.

rust-analyzer taking 2GiB of RAM per instance definitely hurts. And I agree that efforts to reduce this are noble and warranted, but I worry about what doesn’t happen because of those optimisations. The rust tooling is just so-so good (and a better argument for the language than memory safety imo), so I support more efforts to be ergonomic over memory optimisation. Even though rust-analyzer is often the largest memor…

It wasn't long ago RA was consuming over 24GB for my main workspace. They've been working on memory use and it dropped to ~7.5GB for a while but the last couple of releases have been nudging up again - currently 9.4GB without major change in the workspace. It becomes an obstacle on a 64GB machine given I work with multiple workspaces open e.g. for the crates I am using, example projects, other branches etc. so I have…

We're still working on it! The last release had https://github.com/rust-lang/rust-analyzer/pull/23079 which is a significant savings, and I already have more baking (some even have a PR).

We're also working to resolve the issues with `rowan` (it's a GSoC project), which should give another major saving.

Re: Rust Glancer: Rust LSP using 100x less RAM

#129
post #39

Earlier quoted context omitted.

But RA already eats up huge amount if storage when working in a large project, if you're using disk cache, it'll gobble up more, That's the biggest complain I had with RA. Somehow never had this issue with jetbrains rust plugin.

I’m not sure if RA intentionally uses storage space itself. It can use storage when running build scripts/expanding proc macros, or when running flycheck diagnostics. In both cases, it’s because it runs cargo and it writes artifacts to the target dir. And if features do not align between “common” cargo commands and configuration rust analyzer has, it can lead to conflicts and even more increased storage size (because…

r-a has zero filesystem writes (except minor things like copying lockfiles). All the filesystem bloat is from Cargo and rustc.
Post reply on HN