question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compiler service: file parsing should use caching.

See original GitHub issue

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:

  1. Modify A.fs,
  2. Open C.fs, file B.fs is parsed again. Files A.fs and C.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: https://github.com/dotnet/fsharp/discussions/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.

Issue Analytics

  • State:open
  • Created 7 months ago
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
safesparrowcommented, Mar 6, 2023

Instead a new SyntaxTree is being instantiated on every edit. 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. This issue is primarily about parsing files as part of a chain of parse+typecheck operations. Please have a look at the example in the description with the three file project.

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. Compare it to parsing all files in the project after only one of them has changed - all but one request could be cached. I believe the “active file edit” scenario is also why some endpoints have the cache argument which is sometimes set to false by the caller.

1reaction
auduchinokcommented, Mar 6, 2023

It would be nice if ParseAndCheckFileInProject could cache previous files trees in some cache indeed.

I believe the “active file edit” scenario is also why some endpoints have the cache argument which is sometimes set to false by the caller.

Yes, exactly. We’ve added it when started doing additional parsing that we didn’t want to be cached anywhere.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code caching for JavaScript developers
(Byte)code caching reduces the start-up time of commonly visited websites by caching the result of JavaScript parsing + compilation.
Read more >
In C++, should I bother to cache variables, or let the ...
At first glance, I thought the compiler could generate equivalent assembly for both versions with optimization flags activated.
Read more >
ccache(1)
Ccache is a compiler cache. It speeds up recompilation by caching the result of previous compilations and detecting when the same compilation is ......
Read more >
Should ScssPhp provide the Cache mecanism? · Issue #316
That said, parse cache should not assume that the files are in the filesystem, either (some hosts make filesystem read-only and force to...
Read more >
C/C++ extension FAQ
The language server caches information about included header files to improve the performance of IntelliSense. When you edit C/C++ files in your workspace ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found