Cache find_client_win results to avoid repeated XQueryTree scans - #41
Open
jEsuSdA wants to merge 1 commit into
Open
Cache find_client_win results to avoid repeated XQueryTree scans#41jEsuSdA wants to merge 1 commit into
jEsuSdA wants to merge 1 commit into
Conversation
find_client_win() recursively calls XQueryTree() to locate the actual client window within a toplevel window hierarchy. This is expensive and currently called on every frame for windows where the hidden state is unknown or for every call to get_frame_extents(). Add a client_id_resolved flag and client_id Window field to the win struct. The first call to find_client_win() stores the result; subsequent calls reuse the cached value. This eliminates the repeated XQueryTree scans. The cache is invalidated on ReparentNotify events because the window hierarchy may have changed (e.g., when the window manager restarts and reparents windows).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Caches
find_client_win()results to eliminate repeated expensiveXQueryTree()recursive scans on every frame.Problem
find_client_win()recursively callsXQueryTree()to locate the actual client window within a toplevel window hierarchy. This is expensive and currently called:get_frame_extents()(which reads_NET_FRAME_EXTENTS)win_paint_needed()when the hidden state is stillHIDDEN_UNKNOWNFor windows without a client window (e.g.
override_redirectwindows, or windows where the WM doesn't create a client), this results in a full recursive scan of the window hierarchy on every frame.Solution
Add
Bool client_id_resolvedandWindow client_idfields to thewinstruct. The first call tofind_client_win()stores the result; subsequent calls reuse the cached value.The cache is invalidated on
ReparentNotifyevents because the window hierarchy may have changed (e.g., when the window manager restarts and reparents windows).Changes
cm-window.h— addsclient_id_resolvedandclient_idfields towinstructfastcompmgr.c— uses the cache inget_frame_extents()andwin_paint_needed(), invalidates on reparent inadd_damage_if_hidden_changed()Scope
cm-window.handfastcompmgr.conlymake clean && makeproduces zero warnings, zero errorscalloc()inadd_win()Impact
Eliminates repeated
XQueryTree()recursive scans for windows whose client window doesn't change. Most noticeable for windows without a client (e.g.override_redirectpopups, menus), which previously triggered a full hierarchy scan on every frame.