-
Notifications
You must be signed in to change notification settings - Fork 805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiler service: file parsing should use caching. #14848
Comments
Hi @safesparrow, can you try to run my draft #14849? This is VS only now. |
@majocha Thanks for looking.
|
It does do a little bit more 😉, cache sizes are increased just to test it.
|
It should reuse cached parse results throughout now when |
Can you elaborate on whether it affects this particular callsite from point 2. above: As I understand and as tested in Rider, this callsite is responsible for most indirect parsing actions when type-checking of a chain of files is triggered.
Maybe I'm missing something, but I don't see anything in the PR that would use the cache in 2. |
@safesparrow I'll have to look into it when I'm back at my PC 🙂. From what I see , what I tinkered with was much closer to the surface.. |
So IIUC the parse cache we have in service.fs is almost useless, because |
Almost, yes. Specifically, Rider uses the |
This caching mechanism does not seem to be working at all: This is never ever hit Instead a new Some parse calls are there for diagnostics and there is a lot of setting things up involved (side-effects, too, I believe). It does not look practical to cache every call in a centralized way. |
I think we need to get on the same page. Parsing on edit is different. There is little point caching those requests as the chance of seeing exactly the same source code upon multiple edits is small. |
It would be nice if
Yes, exactly. We've added it when started doing additional parsing that we didn't want to be cached anywhere. |
@safesparrow that's exactly the scenario I stepped through in the debugger. I modify file A and see SyntaxTree ctored for file B each time. |
SyntaxTree object might be constructed, but hopefully the actual parsing ( I don't think the weakCache mechanism is relevant here. You'll want the |
Yep, that's what I meant.
Yes, I just tried this. I was hoping to use |
@safesparrow I did a quick and dirty draft to start something. This should already work. OK, maybe it's placebo but editing service.fs no longer feels like wading through mud. |
Is your feature request related to a problem? Please describe.
IDE interactions are slow, partly because the same files with unmodified contents are parsed multiple times, with no caching mechanism.
Given a project with three files:
A.fs, B.fs, C.fs
, every time I:A.fs
,C.fs
,file
B.fs
is parsed again. FilesA.fs
andC.fs
are probably parsed again too, although I'm not sure exactly when they are, and the main point is that all files for which typechecking is performed, are parsed again.Note that I've only tested this in Rider.
Describe the solution you'd like
Introduce a caching mechanism with size configurable by consumers of FCS, which avoids parsing the same files again if nothing relevant has changed.
Additional context
Note that there is a parsing cache, but it's only utilised by the dedicated file parsing endpoint, and is not used when the typechecking endpoint is called instead.
Also note that there seem to be multiple ways in which parsing is called, with different stack traces.
The cache should address all of them if possible.
Also note that if this ends up using
SourceText.GetHashCode
, that method is quite slow as it has to scan the whole source.It might be worth considering calculating the hash once upon creation of
SourceText
.Related discussion I started: #14199
Related: Idea of parallel parsing in the FCS.
I briefly looked at the possibility of parsing project files in parallel in FCS. However, the complexity of IncrementalBuilder makes it rather difficult.
Also, once we have a caching mechanism with a large-enough size, the marginal gain of parallel parsing would be limited to speeding up the first-time typechecking after starting the IDE.
The text was updated successfully, but these errors were encountered: