Discussion thread for https://github.com/rust-analyzer/rust-analyzer/issues/8663
what kind of thing would get put into the scratch space? I'd think the biggest parts of the work happen behind salsa queries. Maybe that's not true for things like highlighting
Nothing in particular, but it feels like we might be doing some allocs:
λ rg collect crates/ide/ | wc -l
assists often allocate a buch for the final edit
but yeah, threading this to the salsa would be nice. Although it's unclear how to best to that
a naive apporach is to use one scratch space for the whole end-to-end query, but I fear that that might be too much
like, the root query might be "typecheck the world", and, in that situation, not freeing anything at all until the very end seems to be excessive.
I guess, in an ideal world this should look like this:
In this scheme, unlike "a scratch space for top-level query", we only keep scrats space for the stack of active queries, and that's bounded
So, eg, this Vec looks like it could ideally be allocated onto some arena: https://github.com/matklad/rust-analyzer/blob/7bb9c147c0e4815ff8ed48dfee1d8267133bbef7/crates/hir_ty/src/method_resolution.rs#L904
Although maybe what we need here is just
alloca and huge stacks?
I was about to ask, why not just create a new arena owned by the query function? (or maybe those arenas could be pooled)
Oh, does this show up in profiles?
Yeah, that's a better way to do that :)
@Jonas Schievink [he/him] this = allocations?
Not really, and that's why I am conflicted here
Doing per-request arena is obviously the right way to approach this on the one hand, and it has significant architectural implications (retro-fitting arenas is painful).
But it is probably not the biggest perf sink at the moment for us
I wonder if you could hide this with TLS or something for each request.
No borrows of anything inside of a thread local can escape the
MY_TLS_VAR.with(|my_tls_var| /*...*/) closure without unsafe code. That includes anything allocated inside the arena. I think it won't be easy to make the unsafe code sound.