Skip to content

Windows dispatcher idle performanceΒ #19082

@ltetak

Description

@ltetak

Describe the bug

I see a blocked CPU time on Windows dispatcher (main thread). Around 10% on my machine. It might be just my incorrect measurement, but if true, then it is quite a significant performance hog.
I assume the problem is that scheduling and killing the system timer is not optimal.

Image

To Reproduce

Run an empty app on Windows.
Performance profiler says UpdateTimer method takes ~10% of the main thread time. This is a problem if you want to run a lot on the main thread. You can not use it up to 100%.
CPU usage is around 0.3%, which is almost nothing. But those 10% are probably blocked and unusable anyway.

Expected behavior

idle time is 0% CPU wasted, no blocked main thread
When I run the app and then comment out the UpdateTimer method, I see the dispatcher thread still ticking, and there is no blocking and 0% CPU in Task Manager.

Avalonia version

11.3.1

OS

Windows

Additional context

UpdateTimer method
https://github.com/AvaloniaUI/Avalonia/blob/master/src/Windows/Avalonia.Win32/Win32DispatcherImpl.cs#L41

Note that the Windows timer granularity is 15.4ms, so 1ms as a minimum is very optimistic. But that still means this method is invoked a lot of times per second.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions