Open JVApen opened 1 month ago
@JVApen What makes you suspect that the CMake Tools extension is what crashes the extension host? I ask because the thing that makes you suspicious of the extension may be helpful in understanding the issue and investigating.
Multiple reasons. It is nicely timed with the configuration that is finished. It shows some message about the extension crashing/exception (I haven't been able to screenshot in order to read it) at the location it indicates the configuration is ongoing. When I disable the extension or cancel the configuration, the crash doesn't happen. I can't exclude another extension reacting on something that the cmake tools initiates. Though even with the log level trace enabled in VS Code, it doesn't even mention why it crashed.
@JVApen Interesting, definitely sounds suspicious, could you attempt to send us a repro project, as well as a recording (a .gif should be fine) of the issue? I wonder if you can get a screen recording maybe we can see the error message
That is going to be challenging as it is linked to a large proprietary project, so I'll need to manually reduce it. That's going to take some time
Together with a colleague, we've found what was happening. We basically encountered https://github.com/microsoft/vscode-cmake-tools/issues/970 Though there is nothing in VS Code that even gave the hint of an out of memory.
It seems that when loading the compile_commands.json of only 375MB, the process starts using 4.5+GB, after which it hits a limit and disappears. I find a +10x memory usage quite excessively as memory usage for reading in the file that is only selectively used later on. If I read the code correctly, it makes a full in-memory copy of content of the file to store in a map. As optimization, it could only store the filename and the offset in the file, and extract the compile command the moment the data is actually needed. (At least, that's what I would do in C++, I don't know if typescript is powerful enough to do the same)
@JVApen Thanks for the investigation! So, you're saying that you think the issue is that we're storing the entire file? Or is it because of how long it takes to read the file?
I believe it is because you are storing way too much. If I look at the class CompilationDatabase, it looks to me like it reads the whole file and stores all the info in a map, such that it is available for later use
@JVApen Ah, got it. And that's where your suggestion comes in, you're suggesting that we instead, we opt for only reading the file when we actually need to access the file? I'm not 100% familiar with how to access the file location by offset, since it's JSON and I'm not sure whether or not typescript allows for that low level of manipulation.
This presents an interesting problem, because I'm sure the reason that it was stored to begin with is because of the perf hit that we would get if we read the file in every time we want to access something from it
Sounds indeed like an interesting challenge. Did you parse the whole file when you did so?
What I'm suggesting is:
You can also take the whole file in memory and store string views to it. Some quick Googling gave me https://github.com/epoberezkin/json-source-map which seems to have do something like this.
Regardless, my expectation for a 400MB file would be at most 100MB on caching structure around it.
Brief Issue Summary
As soon as CMake Tools is done with configuring the project, it crashes the extension host. The same happens if I use an already-configured configuration, where it only needs to read the cache. I haven't been able to get much details, so any hints on how to provide extra information is welcome.
CMake Tools Diagnostics