I'm currently learning Python. For that, I'm an programming a stupid tool that draws stuff around the mouse cursor. It has either a particle effect or a relatively static display of the time, the color underneath the cursor, or something like that. One would expect the particle effect to be the only one causing DWM to spike in CPU usage, but it's everything.
Using Process Hacker I can see that this thread of DWM is taking up all the CPU time dwmcore.dll!MilTransport_Release+0xXXXXX. MilTransport_Release is a function inside the dwmcore.dll. No Information about it is available, afaik.
What does that mean?
Here's a minimal example. Press ESC to kill the process.
import pygame
from win32gui import SetWindowLong, SetLayeredWindowAttributes, GetWindowLong, SetWindowPos
from win32con import HWND_TOPMOST, GWL_EXSTYLE, SWP_NOMOVE, SWP_NOSIZE, WS_EX_TRANSPARENT, LWA_COLORKEY, WS_EX_LAYERED
from win32api import RGB
def setWindowAttributes(hwnd):
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE)
SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_TRANSPARENT | WS_EX_LAYERED)
SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), 0, LWA_COLORKEY)
def loop():
looping = True
while looping:
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
return
display_window.fill("#000000") # fill with transparent color
print("running")
clock.tick(60)
pygame.display.update()
pygame.init()
display_window = pygame.display.set_mode((0, 0), 0)
setWindowAttributes(pygame.display.get_wm_info()['window'])
clock = pygame.time.Clock()
try:
loop()
finally: # to catch all things and quit correctly
pygame.quit()
(This is not running in the background.) It creates a 60 fps fullscreen transparent layer that is topmost and clickthrough. If you don't click anything after you started it, press ESC to kill it.
On my crappy laptop this minimal program makes DWM use 25% CPU (one full core) and 20 to 25% of the APUs GPU. (It's a AMD A4-6210) On my AMD Ryzen 5 2600 it is similar, maxing out one HT core, but that's not as bad.
Behaviour:
The lower the FPS the lower the CPU usage of DWM, but 60 should be totally normal FPS.
The smaller I make the window that's updated, the fewer ressources needs DWM, but fullscreen shouldn't be the issue.
This can't be correct behaviour, can it?
Do you have any information about this? Anything, like how your fullscreen pygame works together with DWM, might help.
Thank you!