Skip to content

libde265: Use process-local sync primitives on Windows. #480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nsivov
Copy link

@nsivov nsivov commented Aug 5, 2025

This issue came up when running libheif+libde265 using Wine,
manifesting as severe performance degradation.

Windows-specific code is using Win32 mutex for cross thread
synchronization, both directly and to implement conditional variables.
This is problematic on Wine because it causes global state change
exchange on every mutex access. On Wine NT objects state is
managed in a separate resident process, each user process communicates with it
to update object state. High frequency access is going to cause
performance problems as a result. Performance will degarde further
if multiple process are running at the same time, each using same
large amount of such calls.

Proposed change is using API that is available since Windows Vista.

nsivov added 2 commits August 5, 2025 16:56
This issue came up when running libheif+libde265 using Wine,
manifesting as severe performance degradation.

Windows-specific code is using Win32 mutex for cross thread
synchronization, both directly and to implement conditional variables.
This is problematic on Wine because it causes global state change
exchange on every mutex access. On Wine NT objects state is
managed in a separate resident process, each user process communicates with it
to update object state. High frequency access is going to cause
performance problems as a result. Performance will degarde further
if multiple process are running at the same time, each using same
large amount of such calls.

Proposed change is using API that is available since Windows Vista.

Signed-off-by: Nikolay Sivov <[email protected]>
@farindk
Copy link
Contributor

farindk commented Aug 6, 2025

Thank you for this. That's really helpful since I am not a regular Windows (or Wine) user.

I am wondering: libde265 was written before C++11 was widely available, but now, we could simply use std::mutex and std::condition_variable instead. Do you know their performance on Windows compared to your proposal?
If needed, I could make the changes and you could maybe benchmark them on Windows?

These references seem to suggest that using the C++11 types might be even better:
Why did CRITICAL_SECTION performance become worse on Win8
How is CONDITION_VARIABLE implemented?

@nsivov
Copy link
Author

nsivov commented Aug 6, 2025

Yes, I think this will work just fine. I see libde265 is already using std::mutex for library init/deinit functions, so it won't be a new addition. The build I tried was using VS 2022, using std::mutex and std::condition_variable will link to msvcp140.dll for sync functions, and already does for existing std::mutex.

Regarding CRITICAL_SECTION on Win8 point, I checked what we have implemented in Wine for CRT, and we do indeed use CONDITIONAL_VARIABLE + SRW for those functions, for newer runtime versions. So that checks out.

So yes, I'd be happy to test the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants