Skip to content
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

1.8.1 has high cpu usage #75

Closed
Fr0stX76 opened this issue Dec 21, 2021 · 7 comments
Closed

1.8.1 has high cpu usage #75

Fr0stX76 opened this issue Dec 21, 2021 · 7 comments

Comments

@Fr0stX76
Copy link

Describe the bug
1.8.1 has high cpu usage reported in W10 task manager and Hwinfo which create latency in games. Rolling back to 1.7.19 fixes the issue.

To Reproduce
Steps to reproduce the behavior:

  1. Go to task manager
  2. Click on monitoring
  3. See cpu consumptiion

Expected behavior
normal (under 1%)

Files
Add logfile, UserSettings.json and, if applicable, screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: W10
  • Version 20H2

Hardware (please complete the following information):
-Monitors: Samsung QN90A
-Graphics card: Strix 3080
-Graphics card driver: 471.96
-CPU: 10700K l(5Ghz all core)

@res2k
Copy link

res2k commented Dec 21, 2021

Probably b/c AutoHDR is constantly polling for monitor changes (UpdateMonitorLoop()), with a very short interval between checking for monitors (100ms, afaics).

Better would be to handle monitor changes as they occur.
At least on Win32 there's a message for that (WM_DISPLAYCHANGE, IIRC).

However, it's not entirely straightforward to get messages, as AutoHDR is mainly written using WPF...

I looked around a bit, here's what I found, not sure to the extent that helps, or how to best fit it into AutoHDR's architecture:

diff --git a/Source/AutoHDR/Views/AutoHDRMainView.xaml.cs b/Source/AutoHDR/Views/AutoHDRMainView.xaml.cs
index 30a057a..c060978 100644
--- a/Source/AutoHDR/Views/AutoHDRMainView.xaml.cs
+++ b/Source/AutoHDR/Views/AutoHDRMainView.xaml.cs
@@ -1,8 +1,10 @@
 using AutoHDR.Properties;
 using CodectoryCore.UI.Wpf;
+using System;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
+using System.Windows.Interop;

 namespace AutoHDR.Views
 {
@@ -27,8 +29,8 @@ namespace AutoHDR.Views
             this.Hide();
         }

-

+        private HwndSource hwndSource;

         private void MainWindow_Loaded(object sender, RoutedEventArgs e)
         {
@@ -38,7 +40,23 @@ namespace AutoHDR.Views
                 Height = Properties.Settings.Default.Height;

             }
-            catch  { }
+            catch  { }
+
+            hwndSource = PresentationSource.FromVisual(this) as HwndSource;
+            hwndSource?.AddHook(WndProc);
         }
-    }
+
+               protected virtual IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
+               {
+                       switch (msg)
+                       {
+                case 0x007E: // WM_DISPLAYCHANGE
+                    {
+                        // Would update monitors here
+                        break;
+                    }
+            }
+                       return IntPtr.Zero;
+               }
+       }
 }

@duk6046
Copy link

duk6046 commented Dec 22, 2021

me too, usage 5% on i7-12700K, 16GB, RTX3070, Windows11

@Codectory
Copy link
Owner

Codectory commented Dec 22, 2021 via email

@duk6046
Copy link

duk6046 commented Dec 22, 2021

I just run it, not use any functions
I checked again, it was 3~4%

@res2k
Copy link

res2k commented Dec 22, 2021

Nvapi is the „problem“ here. Does the display changed event gets fired for all cases (resolution, refresh rate, color depth)?

Looks like it. I tried changing resolution and refresh rate using the "Display settings" and the message was triggered.

Color depth is a bit more problematic since Windows doesn't offer a (user-facing) way to change the display BPP to anything other than 32bpp.
However, toggling HDR triggers the message, and so does changing the "Output color depth" in the NVIDIA Control Panel.

Last but not least, plugging in (or unplugging) a monitor triggers the message, as does changing between mirroring and extending.

I checked all that using a small test app: https://github.com/res2k/DisplayChangeTest - it prints something to the console when the message is received.

@ajoucap
Copy link

ajoucap commented Dec 22, 2021

me too high usage ( basically 7% ) in 5600x . and memory leaked to 91% (my 16gb ddr4)

Codectory added a commit that referenced this issue Dec 22, 2021
[New]
- Audio actions are back, using code from AudioSwitcher (https://github.com/xenolightning/AudioSwitcher)

[Bug fixes}
- Nvapi causes high cpu usage ( 1.8.1 has high cpu usage #75)
- Refresh rate changing not working for some users (v1.8.1+: Refresh rate switching is broken again #74)
@Codectory
Copy link
Owner

Fixed in 1.8.2

res2k pushed a commit to res2k/AutoHDR that referenced this issue Apr 3, 2022
[New]
- Audio actions are back, using code from AudioSwitcher (https://github.com/xenolightning/AudioSwitcher)

[Bug fixes}
- Nvapi causes high cpu usage ( 1.8.1 has high cpu usage Codectory#75)
- Refresh rate changing not working for some users (v1.8.1+: Refresh rate switching is broken again Codectory#74)
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

No branches or pull requests

5 participants