CefSharp
CefSharp copied to clipboard
Winforms - Tab switch should reduce CPU utilisation
- What version of the product are you using?
75.1.142
-Are you using WinForms, WPF or OffScreen?
WinForms
- On what operating system?
Win7, Win10
- What steps will reproduce the problem? Run cefSharp.WinForms.Example and CefSharp.Wpf.Example, I'm testing the www.ezcarry.com site, which has animated effects on its home page, and cesharp.wpf occupies a very high cpu, nearly cefsharp Double the .winform; in the wpf example, I open the site and switch to the cpu-low tab, the cpu will go down; but the cpu in winform will not go down; and the same is true of the winform, but the wpf version will go down;
I tested it with cefclient.exe【cef_binary_76.1.13+gf19c584+chromium-76.0.3809.132_windows32_client】, and when I opened the above website, the cpu was around 20%, but when I minimized it, the cpu dropped to about 1%
cefsharp. Winform version program minimizes or switches to cpu-low tab, high CPU tab CPU usage has been maintained;
WPF version, if I switch from a high cpu tab to a cpu-low tab page or minimize the browser program, the cpu will immediately drop to nearly 0;
Please use the Bug Report
template provided at https://github.com/cefsharp/CefSharp/blob/master/ISSUE_TEMPLATE.md#bug-report
Please make sure you download and test with the CEF Sample Application
as detailed in the bug report under Does this problem also occur in the CEF Sample Application from http://opensource.spotify.com/cefbuilds/index.html?
Please use the
Bug Report
template provided at https://github.com/cefsharp/CefSharp/blob/master/ISSUE_TEMPLATE.md#bug-reportPlease make sure you download and test with the
CEF Sample Application
as detailed in the bug report underDoes this problem also occur in the CEF Sample Application from http://opensource.spotify.com/cefbuilds/index.html?
I added the bug report now,and I tested it with cefclient.exe【cef_binary_76.1.13+gf19c584+chromium-76.0.3809.132_windows32_client】, and when I opened the website of www.ezcarry.com, the cpu was around 20%, but when I minimized it, the cpu dropped to about 1%;
Please specify the command line args you tested cefclient with.
Version 63 of CefSharp is very old and unsupported, please confirm that version 75.1.142 reproduces the problem. You can use https://github.com/cefsharp/CefSharp.MinimalExample for testing purposes
Please specify the command line args you tested cefclient with.
Version 63 of CefSharp is very old and unsupported, please confirm that version 75.1.142 reproduces the problem. You can use https://github.com/cefsharp/CefSharp.MinimalExample for testing purposes
I am directly double-click running cefclient.exe, no manual settings the command line args
I tested the source code downloaded at https://github.com/cefsharp/CefSharp/releases/tag/v75.1.142; I've opened two tabs now, The first one is high cpu (www.ezcarry.com) and the other is the cpu low web page (www.baidu.com), if I select the high cpu tab, the cpu will go down after the minimize, but I select the cpu is not high tab, and then minimize, cpu does not go down, or keep high cp u state; In another case, when I switch from high CPU tab to cpu-low tab in the wpf version, the CPU also drops, but the winform version does not
To compare with WinForms run cefclient --multi-threaded-message-loop
As per https://github.com/cefsharp/CefSharp/blob/master/.github/ISSUE_TEMPLATE/bug_report.md#bug-report you need to test with the following.
cefclient --multi-threaded-message-loop
In another case, when I switch from high CPU tab to cpu-low tab in the wpf version, the CPU also drops, but the winform version does not
The WPF
version is fundamentally different.
I tested with cefclient --multi-threaded-message-loop, and the CPU will still drop when minimized.
Thanks, I'll have a look when I get a chance 👍
When the frame window is minimized set the browser window size to 0x0 to reduce resource usage.
As per https://github.com/chromiumembedded/cef/blob/c7701b8a6168f105f2c2d6b239ce3958da3e3f13/tests/cefclient/browser/browser_window_std_win.cc#L89
Form minimise resolved in #3116
Control.VisibleChanged unfortunately isn't called when switching between tabs. This appears to be a known quirk of WinForms
.
- https://stackoverflow.com/questions/45184599/visiblechanged-dont-raise-when-not-visible
- http://blog.excastle.com/2004/10/18/controlvisible-ugh/
- https://stackoverflow.com/questions/391888/how-to-get-the-real-value-of-the-visible-property
I have yet to find a message/event that works reliably.
You can manually set the size to 0,0 to reduce CPU usage when the browser is no longer visible. Then restore it's size.
Commit https://github.com/cefsharp/CefSharp/commit/77aed487c973dce798cd2d8f19c9c6b6b82c282b will now handle the OnVisibleChanged
call when the control is manually set to Visible = true/false;
This should simplify implementing your own tab switch logic.
Would could potentially capture ParentChanged
and walk up the tree looking for a TabPage
, subscribe to it's VisibleChange
event. This would only handle the built in tab control, it might be the best we'll get.
I'm open to other suggestions.