`eframe` on Windows high CPU usage due to excessive calls to `glutin::context::make_not_current`
- Dominant language
- Rust
- Stars
- 30.6k
- Forks
- 2.1k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 72
Description
I noticed that my application CPU usage was much higher than expected on Windows. On a similar machine I was seeing 1%-2% usage on Linux, and around 20%-30% on Window while moving the mouse in window (just mouse movement).
After some optimization I got my rendering loop down to less than 1ms and still the CPU usage was too high. I then sampled the CPU with https://github.com/nico-abram/blondie/tree/main and this is the flamegraph that it produces:
As you can see, almost 90% of the time, it is calling the `make_not_current` function, which seems really excessive...
EDIT: I found in the docs [here](https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-wglmakecurrent) that this call flushes the rendering context so probably rendering is just very slow... Still not sure why though.
**Screenshots**

Another flamegraph with Windows Performance Analyzer (similar results):

This shows the call stack a bit deeper:
* opengl32d.dll `wglMakeCurrent`
* opengl32d.dll `bMakeNoCurrent`
* opengl32d.dll `wglMakeCurrent`
* opengl32d.dll `wglMakeCurrent`
* opengl32d.dll `wglMakeCurrent`
* KernelBase `SetEvent`
**Desktop (please complete the following information):**
- OS: Windows
- Version: egui 0.26
Contributor guide
Research direction
Start by tracing eframe's Windows rendering path around glutin::context::make_not_current and reproduce the mouse-movement workload described in the issue. Use the provided flamegraph or Windows Performance Analyzer call stack to identify why wglMakeCurrent is called so often. Done means the excessive calls and associated CPU usage are reduced without regressing rendering.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- computer-graphics, desktop, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100