[PATCH] D49267: [clangd] Watch for changes in compile_commands.json

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 23 05:19:39 PDT 2018


ilya-biryukov added a subscriber: sammccall.
ilya-biryukov added a comment.

@sammccall pointed out that I've been looking at a different layer of caching.
Clangd does per-directory (to avoid reloading compilation database multiple times) and per-file (to avoid calling into compilation database multiple times, it's expensive for our internal CDB) caching of compile commands.
https://reviews.llvm.org/D48071 allows to get rid of per-file cache, but still keeps the per-directory cache, so this patch alone won't fix the problem.

We have a somewhat simple fix in mind: for interactive tools, like clangd, the `JSONCompilationDatabase` could be configured to check for changes to `compile_commands.json` and rebuild the compile commands on each call to its methods, if necessary. E.g. we can still keep the per-directory "caching" of `CompilationDatabase`s inside clangd, but CompilationDatabase instances will start returning new compile commands when compile_commands.json is updated.
This would mean more FS accesses (and, potentially, json parsing) on `getCompileCommands` and the same instance of `CompilationDatabase` will now be potentially providing different compile commands for the same file on different `getCompileCommands` calls.
However,

- The FS access concern shouldn't be noticeable for the clang tools: parsing/preprocessing of files is usually done after the `getCompileCommands` call, so the overhead of files access to compile_commands.json and json reads should be negligible, compared to the work to process C/C++ files.
- The fact that const object now changes seems to be a potential source of confusion for the tools and (maybe?) some of them are not prepared for this, so we should probably allow turning this behavior on and off. clangd (and other interactive tools that might be interested in this), would turn it on, while it will be off by default.

It seems this could be implemented somewhere around the `JSONCompilationDatabasePlugin` pretty easily. WDYT?
I'm also happy to come up with a patch to `JSONCompilationDatabasePlugin`, at this point I'm pretty familiar with it. Unless you think this approach is flawed or want to do it yourself, of course. In any case, please let us know what's your opinion on this.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49267





More information about the cfe-commits mailing list