-
Notifications
You must be signed in to change notification settings - Fork 335
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
API::emit_event behavior is different from a "real" event #631
Comments
I have found that there are more ways to get the slow behavior, even with "real" events: using a timer event: timer t(chrono::milliseconds(5000));
t.elapse([&form]()
{
form.slowAction(); //always slow
}); using a programatically triggered slider value_changed event: // s is a slider
s.events().value_changed([this](const arg_slider& arg)
{
slowAction(); //slow if triggered programatically; fast if triggered manually
});
s.value(10); //slow Triggering it manually makes the action fast. This also happens with a scroll. |
The way you are using root_guard is incorrect, it is a class so it must be tied to a variable. Also I think the root_guard should be just before the call to sub.make_before(WM_KEYDOWN, [&form](UINT, WPARAM wParam, LPARAM, LRESULT*)
{
if (wParam == 'A') {
{
// for lazy updates
auto& brock = detail::bedrock::instance();
detail::bedrock::root_guard rg{brock, form};
form.slowAction(); // Calling the function from here is slow.
//Even emitting the event from here is slow:
//API::emit_event<arg_click>(event_code::click, form.slowActionButton, arg_click());
} // root_guard destroyed
api::refresh_window(form); // refresh the form
}
return true;
}); Results using windows 10 64-bit msvc debug mode.
|
Thank you for finding that mistake! I tried it and the speed problem in my program is now gone. |
The issue / question
I found this problem because my program was too slow. I use a class called subclass found at: http://nanapro.sourceforge.net/faq.htm It allows to redefine the window procedure for a nana window, to intercept windows api messages before nana's window procedure is called.
For some reason, event handlers called by nana in response to real mouse clicks and such are much faster than actions that are initiated in another way. Here's an example (complete compilable code follows):
I tried calling the event handler by using the API:
but that's also slow. I can see the background color cycle through all the colors. Why is the behavior different when the event is emitted by a real mouse click? Is this a problem with nana?
additional information
I measured the time. Here's a screenshot. First I clicked the button. Then I pressed A:
I looked at the source code of nana for a hint why this could be. Why does a real mouse click result in much better speed? How does it know what is and what is not a real click? I see nana's window procedure uses the class root_guard and a comment mentions "lazy update" ( line 46). I thought that had to be it. I tried adding this:
It doesn't help at all. In fact it makes the event slow as well.
I can't figure it out. Anyway, here's a full program with the subclass code that exhibits the behavior:
slow_event.cpp
I compiled it with this command:
The text was updated successfully, but these errors were encountered: