Skip to content

compat/poll: load user32 only when poll() runs - #6512

Open
azchohfi wants to merge 1 commit into
git-for-windows:mainfrom
azchohfi:compat-poll-lazy-user32
Open

azchohfi wants to merge 1 commit into
git-for-windows:mainfrom
azchohfi:compat-poll-lazy-user32

Conversation

@azchohfi

Copy link
Copy Markdown

On Windows, poll() in compat/poll/poll.c waits with MsgWaitForMultipleObjects() and pumps
window messages with PeekMessage(), TranslateMessage() and DispatchMessage(). These are the
only functions git.exe imports from user32.dll, so every Git process loads user32, and with it
gdi32, gdi32full, win32u and imm32, even though most commands never call poll().

This loads the four functions with the existing lazyload.h helpers the first time poll() runs.
If user32 cannot be loaded, the process cannot have a message queue to pump, so it waits with
WaitForMultipleObjects().

git.exe then maps 17 images for git --version instead of 23. On a Windows 11 desktop, built
from v2.55.0.windows.5 with and without the change, 100 interleaved runs each:

before after saved
git --version 15.5 ms 13.2 ms 2.2 ms [2.0, 2.4]
git rev-parse --git-dir 17.5 ms 15.2 ms 2.3 ms [2.0, 2.4]
git status --short 48.5 ms 46.2 ms 2.0 ms [1.7, 2.2]
git log -1 --oneline 20.4 ms 18.0 ms 2.3 ms [2.0, 2.5]

t0061-run-command, t5400-send-pack and t5601-clone pass with the change, on the release and
on main.

The same code is in upstream Git, so I can send it to the mailing list too if you prefer it to go
upstream first.

I used GitHub Copilot to help investigate and prepare this change. I have reviewed and tested it.

On Windows, poll() waits with MsgWaitForMultipleObjects() and pumps
window messages with PeekMessage(), TranslateMessage() and
DispatchMessage(). These are the only functions git.exe imports from
user32.dll, so every Git process loads user32, and with it gdi32,
gdi32full, win32u and imm32, even though most commands never call
poll().

Load the four functions with the existing lazyload helpers the first
time poll() runs instead. If user32 cannot be loaded, the process
cannot have a message queue to pump, so wait with
WaitForMultipleObjects().

Signed-off-by: Alexandre Zollinger Chohfi <alzollin@microsoft.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant