-
Notifications
You must be signed in to change notification settings - Fork 669
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
["BUG"] Foam Graph uses inappropriate amount of CPU #347
Comments
I tried to reproduce and wasn't able, is the repo in question private or would you be able to share it as a means to find out more? |
I have the same issue on all of my projects. |
I really need more information to work on this @everydayanchovies @fmagin |
Can you tell me what you would do to investigate this? I doubt that the specific structure of the graph is the issue, but I might be able to dump the structure of the graph myself, or just attach some profiler to it to find out which functions are actually hogging all that CPU time. I just don't know which profiler is a good choice for that, but I'd expect that to be about as much work for me as cleaning and sharing my repo in a way that doesn't expose private information |
Given, that the repo is private, if you could provide a view over the VSCode processes running when the graph is up and profile with the devtools that would be a great starting point. Also please provide details over OS, VSCode version (numbered and "edition" - e.g. VSCodium, etc) and number of notes in your graph (if possible) |
I get it, how can I profile this? I just cloned the foam bubble template repo and opened it without modification, opened the graph, let it rest and checked cpu usage with htop. All four cores showed 9% usage from primarily vs code. Closing the graph made the cpu usage go down to 0% to 1% across all cores. This is reproducible 100% of the time.
These are all processes that get spawned with the graph (all at once). Closing the graph removes these processes. Let me know how I should profile this. |
Sorry, I see you already mentioned using the dev tools. |
Here is a profile where I started with the graph closed, opened the graph and waited, and closed the graph. |
@everydayanchovies is that graph from VSCode running only the Foam extension(s)? |
I disabled everything but the recommended extensions and repeated my test, same results. I then disabled everything but foam and repeated, no difference. I really think this is a bug in the graph, could you point me to the code that is responsible for rendering it? I would like to take a look @jmg-duarte , maybe I could help. |
If I had to guess I would say the janitor runs too often (does it run on every file change? Maybe that gets triggered every couple of millis due to some bug), or the graph renderer is refreshing the view constantly. I'm tight on time with other projects going on but I did try to get a feel for the codebase, maybe I can look into this later but some pointers would be appreciated. Is this not reproducible on your end? |
From the Chrome traces, the CPU seems to suffer the most during the opening of the graph, which would make sense. I do have an idea though, since the graph runs in WebGL, are you running your project with an integrated GPU? |
In my case it definitely is not running on an integrated GPU, because I don't have one. CPU is a Ryzen 5 3600, GPU is an RX 5700 XT. One interesting thing I just noticed: When the window shows the full graph of around 900 nodes, the CPU hogging process with the argument I agree with @everydayanchovies suspicions that this is the graph constantly being redrawn for some reason. My specific system information is: |
Other weirdness: The processes are still taking up the same amount of CPU, even if I pause the main thread via the developer tools. So I guess it can't be something in the main thread that keeps updating the graph? But I know too little about electron in general to make much of this. |
@fmagin could you post a print of the VSCode process explorer? Not the system one, the one VSCode provides. |
I'm running two systems, both unable to reproduce. I just noticed something. You're running Code OSS and not VSCode (please do make this distinction in the future). I suspect that the best we can do is to get another graph library but we'll see |
I’m using the regular VS code package as supplied from Microsofts website, IIRC. Also, I did see the cursor bug you linked earlier and concluded that it did not effect me, but that’s probably because they resolved it already. I assume the same underlying cause could be causing this bug. I will check my VS code version ASAP, am currently afk. |
@jmg-duarte what do you mean by "another graph library"? I think the underlying graph library is not the issue, but the actually rendering itself. But maybe this is still the same library in the case of foam. I grabbed the |
is this happening across computers and repos? that is:
Also:
The graph is continuously rendered because the physics engine updates the location of nodes even when there are no changes. Still, I have seen this handle a ton of nodes, so I am really surprised by the issue. Can you check how your computer manages the following:
FYI this is the library we use: https://github.com/vasturiano/force-graph |
Yes, this does happen both on my laptop and my desktop with the same repo. And it also is an issue with multiple repos on my desktop, haven't checked another repo on my laptop yet. The CPU load is actually quite similar when I open the two graphs you provided with chromium. The basic graph has the render process at 60%, and the gpu-process at 25%, the large graph at 108% and 20%. So I guess this is a library issue after all and not even related to electron itself. This is also an issue in Firefox, though the specific process names are different. |
If the issue was regarding VSCode/Electron/Chromium I'm quite sure that it would've been noticed and fixed already, since we are not the only users of such graph libraries. Regarding the "redraw" issue. The graph has to be drawn to screen every frame, that's just how rendering works. Now the work done for each frame, can and should be adjusted. If the graph is loaded and rendered every frame, that is an issue, since it should only be loaded once. Finally, about the library, I question if we need "forces" for the graph. It's cool but we also don't really take advantage of it. |
Well yes, it has to be redrawn for each frame but not rendered for each frame. But this is splitting hairs with terminology that I am not that familiar with either. The thing is that the CPU load for the huge graph Riccardo linked and my medium size graph of ~1000 nodes in Foam is basically the same, ie. between 105% and 110% for the There is an open issue about performance here vasturiano/force-graph#169 so it might be worth to move this discussion to that or another issue of the graph layout/rendering library. |
I agree on every one of your points @jmg-duarte , also note that the colajs demo loads very smoothly on my iPhone but stutters significantly on the machine I tested this issue on. There may be something wrong with my graphic acceleration? |
For what it's worth I am also using i3wm (mostly without compton though). Direct rendering is also enabled/supported. |
However, once the movements settle the graph is stationary (obviously), and CPU usage goes down to ~1%. So I would prefer to see colajs used seeing as the forces between nodes and the subtle movements are not really adding anything of value. I'll try to implement it this weekend and see how far I get. |
So I tried this on two other setups, one laptop running XMonad and a desktop running Windows. I'm wondering how platform specific this might be |
I can replicate this on my private repo. The markdown links view shows 280 files with 2301 links. Mac OS 10.15.7. Using VSCodium 1.53.2. As soon as I open the Foam Graph view I get two processes that together consume 120-150% of the CPU. They’re labeled VSCodium Helper (Renderer) and VSCodium Helper (GPU). |
I started implementing colajs but didn't have time to finish and I didn't make any progress, I mostly struggled with learning VS code development and typescript. I'll come back to it when I have more time. |
@everydayanchovies Me and @riccardoferretti thought about it but considered that colajs would not be viable in large repos such the one @fmagin has |
Describe the bug
As soon as I open the Foam Graph two electron processes starts hogging a questionable high amount of CPU performance. On a workspace with around a dozen notes(i.e. nodes in the graph) they are both between 10% and 15% while on a workspace with ~330 notes one is at roughly 65-75% and the other at a quite stable ~24-26%. Numbers according to
htop
and on an AMD Ryzen 5 3600This is without any interaction with the graph and even if VS Code is on a workspace that isn't even being displayed
To Reproduce
htop
for the current list of processes requiring the most CPU performanceExpected behavior
Not hog an absurdly high amount of CPU performance. The Markdown Links graph requires a similar amount of CPU when opening it and occasionally during panning, but this returns to baseline shortly after again.
Additional Notes
I assume this is something with the interactivity and live update feature. Potentially this could be deactivated via an option until the exact cause of this issue is found.
The text was updated successfully, but these errors were encountered: