-
-
Notifications
You must be signed in to change notification settings - Fork 622
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]: Querying windows every event causes significant CPU usage #1852
Comments
I tried on Fluxbox. I can confirm that there is a significant delay on the hover events. And Conky's cpu usage jumps really high as well.
Seems like this is where it starts going wrong. EDIT: Nope...The delay happens before that. I bypassed it. The delay and cpu usage jump was still there. |
Hmm... Most work happens while trying to figure out which window to send the event to. Which also, if that's the problematic part, won't be fixed by disabling BUILD_XINPUT. Mouse click is the simplest event to handle as well, so it doesn't make sense for it to be held up there. I won't be able to fix this until later this week though due to midterms. Personal note while fixing this: Added conky atoms for tweaking XInout behavior might not be needed in most cases - normal windows get correct relative/absolute values and only other types (myb root as well) seem to always get absolute values on Open box (check other WMs, might be an Openbox thing). |
Update: Conky also makes Xorg jump really high in cpu usage. They both jump together. The outlier I found was jwm. It does not seem to care about the hover events. Fluxbox seems like the only one with more delay in the hover events, therefore making it look like the menu is delayed. I testsed on MATE and KDE Plasma, same high cpu usage on hover events. There's some back and forth going on between Conky and Xorg. I will jump in the code later to find out what's causing the sudden high cpu usage in Conky and Xorg |
I just noticed something peculiar The hover doesn't have to be on Conky...I can move the mouse anywhere else, Conky and Xorg will still jump high in cpu usage. As long as I am moving the mouse, the cpu usage remains high. Jumps even higher when the hover is on Conky itself. This doesn't happen when Conky is not running. This behavior is not limited to Fluxbox. Happens elsewhere as well. EDIT: This could be a more significant issue depending on the hardware, such as the person who originally posted about this. |
No, it's because conky is making a lot of X11 requests to query the window underneath it every pixel it moves.
Also why. It's tracking events globally. |
We could cache window AABBs in order to reduce the number of calls and processing needed. I just need to figure out how we can listen to changes to I maybe focused too much with correctness because lack of I think I'll feature gate this fallback with an off-by-default compile flag in case someone has a beefy computer and doesn't mind, and otherwise fallback to old behavior of using I can probably update AABB cache using MapNotify, UnmapNotify, VisibilityNotify and ConfigureNotify events. Nice thing about having that cache in conky is that window variables can also use it. |
The problem I reported is fixed at my place by disabling BUILD_XINPUT. 👍 |
Which version are you on? |
I was too caught up in the previous Conky behavior with hovering over Conky. I hadn't realized this was new. I have to agree. This new behavior is too resource intensive. If someone is working on say GIMP or any other application that requires alot of mouse movements, they might not appreciate Conky taking up so much of the resources. Wouldn't it be better just to deal with mouse events ONLY if they happen on the Conky window? The only usual/normal use case is DE/WM menus...Other use cases will have to be more convoluted.
They would have to be really obscure WMs...And as far as Wayland goes, I know next to nothing about it. I don't use it or its window managers. I played around with Hyprland a bit though. All I know is that there's still too many issues with Wayland. I chased JWM down the rabbit hole for a bit and discovered a couple of different behaviors. On JWM the cpu usage of Conky and Xorg do not go as high as as all the others. The second thing is that when hovering over Conky in JWM, That's how it happens mostly, at least. The unusual way to make This is strange because that would mean conky thinks it's both above and below the menu. |
I tested BUILD_XINPUT with 1.19.7 and 1.20.1, in both cases the compile option solves the issue. |
Tried that initially and it doesn't work for some window types -
This is an X11 bug/thing. Wayland worked flawlessly across all compositors I tested, with only 20 lines of dead simple code....
Right... that's a separate bug then.. I have to examine the window tree for both JWM and fluxbox.
Thanks. I might produce a debug branch that spits out some additional debug information at some point if I'm not able to reproduce the issue. |
own_window=false is only for tiling window managers, right? If own window is true on tiling WMs, then conky gets tiled like any other window. And as far as floating WMs go, own_window=yes, and own_window_type=normal should be the default/recommended setting. I have not investigated any differences in DEs when it comes to own_window_type=desktop/normal yet.
You mentioned dwl, so I thought maybe the changes had something to do with Wayland or Xwayland.
I didn't mean to present the JWM interaction as a bug. It was just something quirky I noticed. JWM works normally for the most part. Better than others, infact. The menu shows up on right click as well. It's just the hover/motion events that behave differently. Other than that...I have been investigating the events with the xev tool. From what I have seen, EnterNotify and LeaveNotify events are all there. EDIT The EnterNotify and LeaveNotify events are there on both own_window_type=normal and own_window_type=desktop I will update more about this further, if I discover anything else. |
Started working on this, will link PR once I have some working code so the cache idea can be tested. |
So here's something Major In my testing, the compositor is making a difference in floating window managers. If picom is not running, own_window=false will have conky drawing as part of the root window. This behavior is the same across FLuxbox, Openbox, JWM, IceWM, Blackbox And as previously stated, when own_window=true is used then normal/desktop both show EnterNotify and LeaveNotify consistently. (This is independant of picom) EDIT: Tested on version 1.19.8 |
@jborme & @lineage-of-roots, can you test |
I can do the tests, but about 12 hours later. In the meantime, I found this ( I have not gone through the relevent code in conky yet, but this seems relevant to what you mentioned)
Relying on MontioNotify has this drawback/feature. The pointer has to start and end in the desired window. If the code is relying on MotionNotify to know when conky has been hovered over, then this seems most probably where the inconsistency is coming from. EnterNotify and LeaveNotify are consistent. Own_window=false can't generate the event for conky, because conky becomes the same as the root window. There's only events for the root window at that point. |
@lineage-of-roots Ok, but we're not using regular MotionNotify events and instead XInput global ones, so that's unrelated. Enter/LeaveNotify aren't consistent because they don't get reported in a lot of cases (see #1495). Let me know whether |
Merged into |
I built conky after cloning the repository into a temp folder, I think that gives me the most current version. It does not solve the issues, though the exact symptoms are slightly different. fluxbox does not lose "focus" (previously rxvt terminal lost the "cursor" when the bug appeared ), cpu load only goes to a total of 1.5 instead of more as I remember, and the menu takes 7 seconds to appear. |
Alright, I'll do some more testing and try to generate a flamegraph to best see what's the issue as I don't see much performance issues on my side. Just gotta re-learn how to do that 😆 |
I will get to testing shortly...In the meantime I wanted to clear/understand a few things.
I meant previously, when there was no XISelectEvents() In #1495, the first thing I noticed was that Back then we had (We still do have in "fallback" in the current code)
PointerMotionMask is infact, MotionNotify. So it can be inconsistent depending on how it's used. (I have not looked through the whole code though) Interestingly I did not see anything in the code(Current or Previous), referencing ButtonMotionMask
Using it could be useful. Now, just so I understand...We want Conky itself to be interactive with clicks and motion, right? As far as I understand, when own_window=false is used...Interactivity can be difficult or impossible. Because then Conky will be just like the wallpaper. Are we trying to achieve interactivity even in this case? Lastly, Can I also get your conkyrc config with which you would be testing this interactivity, please. |
Did some quick testing. The performance hit is still there. Across all window managers floating/tilling. The peaks vary. Most noticeable in Openbox and Fluxbox. Now even in Openbox the menu can be delayed slightly, depending on how much mouse movement there was. Move the mouse around for a few seconds to see the jump. The performance hit predictably gets even worse if there's more than one conky instance running. Such as when config files are separated. I will later test on my Laptop as well to compare. |
So here are some sources of the performance hit I came across This loop in x11.cc
It will be executed on three separate occasions per pixel move. The three sources of its execution are here in display-x11.cc
These query_x11_*** functions all lead to that loop. Now, numChildren in that function is the same number you get if you do the command Suppose we had 100 children of root, then that loop will run for a total of 100x3=300 times per pixel move in the current code. Another place is in mouse-events.cc
These loops will execute 256+64=320 times per pixel move There are many other executions per pixel move, but these are some of the major ones. EDIT:: On window managers without virtual roots(Openbox, Fluxbox, IceWM to name a few), the above loop with numChildren never breaks. Suggestions We could perhaps do XQueryPointer less often (every 0.1 seconds perhaps?) instead of every pixel move. I bypassed much of the execution just to get ge the x, y position of the pointer, |
@jborme let me know if this issue needs to be reopened. The PR that fixes performance issues has been merged into |
I found some of the answers I was looking for here https://github.com/brndnmtthws/conky/wiki/Mouse-Events However, while trying to test out button functionality, I came across an issue with cairo and pagocairo. (pangocairo is missing from the options. 1.19.8 is linked to both and works with cairo)
It wasn't getting linked, even though it was enabled in the cmake build options. |
Pangocairo is a Wayland dependency and has no Lua bindings. Cairo requires you to enable |
I did that. Turned it on via Same result. |
Ok, let's not comment here as it's not related to this issue. Open a separate issue or comment on the other one (#1867), so that jborme doesn't get notifications about unrelated things. |
Scratch that. I fixed it. It wants libcairo.so in /usr/local/lib/conky now. I just noticed it's closed. Had the link bookmarked in the browser. |
The delay is fixed for me with the latest version |
Originally posted by @jborme in #1821 (comment)
Workaround: disable
BUILD_XINPUT
flag.The text was updated successfully, but these errors were encountered: