Skip to content
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

Cache project config on demand #1000

Merged
merged 10 commits into from
Jun 4, 2024
Merged

Cache project config on demand #1000

merged 10 commits into from
Jun 4, 2024

Conversation

zth
Copy link
Collaborator

@zth zth commented May 31, 2024

Experimental support for caching the project config to speed up analysis.

It should be good enough to merge and get started testing, and we can then polish before making it the default.

You enable it via the rescript.settings.cache.projectConfig.enabled extension config option. It'll then watch build.ninja and build a cache of (some of) the project config, that the analysis can then read as needed and avoid doing a bunch of work.

In larger repos this has shown latency improvements of +8-9x. So a massive improvement.

Running it as experimental for a while to get some feedback, and then hopefully something that'll be easy and risk free to enable for everyone.

if (changedPath.includes("build.ninja")) {
let projectRoot = utils.findProjectRootOfFile(changedPath);
if (projectRoot != null) {
syncProjectConfigCache(projectRoot);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe make this conditional on the setting, so potential issues of writing this file would be contained to having the setting on.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although the watch wouldn't be set up unless the setting is on.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point :)

@zth zth force-pushed the cache-build-state branch from cc5900e to fb6b95a Compare June 4, 2024 07:07
@zth zth requested a review from cristianoc June 4, 2024 07:07
@zth zth marked this pull request as ready for review June 4, 2024 07:07
| None -> []
| Some namespace ->
let cmt = Filename.concat libBs namespace ^ ".cmt" in
Hashtbl.add pathsForModule namespace (Namespace {cmt});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the cache file is read, pathsForModule will already have been populated when this line was executed when creating the cache, and here it is added again.
No consequence I can think of, but good practice to make sure things are not mutated after caching them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Let me think about how to make that better.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's fine to leave in for now. I can't think of a consequence either. Maybe doing a Hashtbl.replace instead of add makes sense though.

Copy link
Collaborator

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to go for people to try as an experimental feature.
Perhaps I'd add a short description in the PR's description that this watches build.ninja and uses it to update a cache of files in the project sources and dependencies.

analysis/bin/main.ml Outdated Show resolved Hide resolved
| Some package -> Cache.cacheProject package
| None -> print_endline "\"ERR\"")
| [_; "cache-delete"; rootPath] -> (
Cfg.useProjectConfigCache := false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem to be used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@cristianoc cristianoc Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I meant to say the line Cfg.useProjectConfigCache := false does not seem to be necessary in the delete command, as none of the code below is affected by it.

@zth zth force-pushed the cache-build-state branch from fb6b95a to dac8ae6 Compare June 4, 2024 12:11
@zth zth merged commit 7c9f1bd into master Jun 4, 2024
6 checks passed
@zth zth deleted the cache-build-state branch June 4, 2024 12:31
jfrolich pushed a commit to jfrolich/rescript-vscode that referenced this pull request Sep 3, 2024
* cache project config on demand

* e2e for the new cache mode

* only look up project files etc when needed

* comment

* Revert "only look up project files etc when needed"

This reverts commit bc71f76.

* remove now irrelevant comment

* changelog

* conditionally

* rename

* replace instead of add
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants