Skip to content

Performance issues on Windows #91

@huntfx

Description

@huntfx

I switched my project to use your library, it calls get_monitors() once per second, and I noticed it was introducing very noticeable lag across my whole PC after a few hours of use. I'd restart the script and it would be fine for a few hours, then it would break again.

There's two separate issues that it causes:


The first is that apparently GetDC can be a blocking call under certain circumstances. In my case, after a few hours, it's getting in a state where it fails the 100 retries on every run. That loop takes around 0.5 seconds to complete, which pretty much completely locks up the PC while it runs, freezing the mouse cursor.

I tested changing the number of retries to 10, and while it did make a difference, the underlying issue was still there and I could see see the little hitches as I moved my cursor across the screen.


The second issue is that it can cause other events to trigger this. For example when Razer Synapse switches a mouse or keyboard profile, it also triggers the same lag spike.

This is independent of the first issue and happens a lot sooner. Stopping calls to get_monitors doesn't fix it - the only solution is to shut down the script, which I guess releases whatever API resources that are causing the problem.


I tested removing the GetDC calls and it fixed both issues.

I'm not sure if there's any alternative, but it seems that particular call comes with potential side effects, that are more likely to happen the more the script is run.

My one idea would be adding a parameter to get_monitors that could optionally disable that feature:

def get_monitors(name, get_physical_size=True): ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions