Since upgrade from V9.1.0 to V9.5.0, we find that the CPU usage is always high in windows, not like before which is 0% in static state.
So, we checked the difference, and we found the Event Loop logic changed. In file Rendering/UI/vtkWin32RenderWindowInteractor.cxx Line386, the while loop is always running, after we insert a sleep in the while loop, the CPU usage is to 0%.
For now, we insert code like this:
while (!PeekMessage(&msg, nullptr, 0, 0, PM_NOREMOVE))
{
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
Before this, we tried to just add one line:
std::this_thread::sleep_for(std::chrono::milliseconds(1));
But, in some progress written by Qt, it is easy to no response, so we changed it.
Would anyone tell us the difference? and is there other way to decrease the CPU usage?
ben.boeckel
(Ben Boeckel (Kitware))
April 1, 2026, 11:27am
2
@mwestphal Your change to also look at inputs looks relevant? @jaswantp You changed timer handling?
mwestphal
(Mathieu Westphal (Kitware))
April 1, 2026, 1:59pm
3
I see a few culprits:
TBF the timer on Windows were basically reimplemented, so its not surprising that this passive behavior was not kept.
@xiaohuijieao feel free to open a PR to improve the current behavior if you want.
jaswantp
(Jaswant Panchumarti (Kitware))
April 1, 2026, 2:30pm
4
It uses busy-wait, so that is the reason for high cpu usage.
pieper
(Steve Pieper)
April 1, 2026, 2:32pm
5
I hope this can be fixed quickly. Well behaved code should never busy wait.
jaswantp
(Jaswant Panchumarti (Kitware))
April 1, 2026, 2:33pm
6
jaswantp
(Jaswant Panchumarti (Kitware))
April 1, 2026, 2:36pm
7
guarded behind a !PeekMessage so that it goes into “sleep wait” when the message queue is empty i.e, vtk window not receiving any user input.
jaswantp
(Jaswant Panchumarti (Kitware))
April 1, 2026, 2:50pm
8
See https://gitlab.kitware.com/vtk/vtk/-/merge_requests/13097
In my local testing:
With my WaitMessage MR
CPU usage goes back to 0% when window loses focus
With v9.5.0
CPU usage does NOT go below 3.0%
It would be nice if anyone of you can independently verify my MR removes the busy wait.