Sarcasm / irony-mode

A C/C++ minor mode for Emacs powered by libclang
GNU General Public License v3.0
901 stars 98 forks source link

Any way to cache compilation_commands.json? #481

Closed tautologyclub closed 5 years ago

tautologyclub commented 6 years ago

Hi,

For large projects (specifically the Linux kernel) I sometimes have to jump around in source files very very very frequently. Every new file I open freezes emacs for a few seconds due to irony looking for, and then parsing, the .json file located in the linux src root. But it's the same compilation database for every file! What's taking time is finding the file and actually parsing the json. Is it possible to cache the contents somehow?

Note: I realize using irony for the linux kernel is a bit unorthodox, but it actually works rather neatly after some doing some drudge work with setting some extra clang options inside .dir-locals.el. So if possible, please refrain from "just don't use irony on the kernel" type advice.

Sarcasm commented 6 years ago

Does it happen for every files, or just header files? It's true that even the C++ version, relying on libclang, opens the compilation database everytime. But if the compilation database is big, you may not want it persistently loaded into memory, so it makes sense IMHO.

If it's the Elisp guess code, for header files, that is slow, then it might be better to disable this backend, and to compute the header compilation database once with a tool like https://github.com/Sarcasm/compdb

tautologyclub commented 6 years ago

No, this goes the same for C files. I don't have the exact size of the json file available, but if it's anything below 2GB I surely wouldn't mind having it in RAM. But if this would take a major refactor to accomplish I completely understand if you're unwilling. You've done a great job with irony by the way, many thanks.

I'd love to know if you think this is a theoretically feasible feature at all though. Maybe I'll try to contribute :)

Sarcasm commented 6 years ago

Can you show me the output of M-x irony-cdb-menu RET? I'd like to know if it's the irony-cdb-libclang backend that find the compile options, or another one.

It would not be too difficult to keep the last database in memory, but I'm wondering if it is necessary at all. If the libclang backend is not in effect, things could get really slow on big JSON files.

tautologyclub commented 6 years ago

I'll get to it when I get back to my work computer tomorrow. But I'm guessing it isn't in effect based on my recollection of the profiler report - it looked like an elisp function doing a ton of json parsing. I'll check though.

Sarcasm commented 6 years ago

Maybe your issue is similar to this recent one:

The reported made a tool to work around the issue.

itollefsen commented 5 years ago

Proposed caching of the latest used compilation database in pr #499.

My compilation databases are frequently in the >= ~12 MB area. Opening a C++ file in such a project would trigger a complete re-read and re-parse every time. On my old machine, that operation would typically take 1 second / MB of compilation database, which made it neigh on unusable.

itollefsen commented 5 years ago

I think this can be closed and considered fixed now that pr #499 has been accepted and merged.

Sarcasm commented 5 years ago

Indeed.