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
RFE: Handling events in batches #422
Comments
For some background, I just checked with Xcode Instruments while scrolling up and down using the mouse wheel, and:
So requesting fewer screen updates should help performance in this case. |
This seems like a reasonable idea. I think I'm kind of liking the latter option. We should probably also offer PostEvents() to be able to post multiple events at once too. |
Hm.... I wonder if it would be better (more idiomatic) to just expose the channel. Applications can then do select {} with a default case if they want to. Sort of like this: func Events() <-chan Event This channel would return events, or nil when the application closes. Thoughts? |
Actually.... PostEvents just posts to the same channel... so maybe that needs to be exposed as well, but have to think about application shutdown looks like. |
But if the channel just exposes a single element, isn't it useless, as you never know whether there's another one in the channel? |
You can select with a default case.
|
Basically I'd have to code up something like the above loop anyway. This would allow applications to inject their own channels into the select, e.g. for network events, timeouts, etc. Which is kind of attractive to me. |
Ah, i thought you mean with events. But you mean returning arrays from the channel? |
No. Read the sample code. Its a single event, but you keep getting them until there is nothing left in the channel. You get a notice that the channel is empty by hitting the default case. |
IMO exposing the channel might be more idiomatic. My subjective opinion is though:
Regarding injecting events, that can already be done using That said, what I really want is to be able to dodge some screen refreshes, and if I will be fine with any API allowing me to do that. |
If I expose the channel then you could just call len() on it. |
FWIW I just tried to work around this by accessing Turns out |
Exposing the event channel turns out to be a bit more complex than I'd like. The issue is dealing with close() of that channel, and handling how that works with respect to posting events. Adding another layer of complexity is the fact that this event channel is a bit abused for multiple purposes. This is because I was rather naive about handling of multiple channels and select, and I just crammed everything into one channel when I first designed tcell. I'm a little more savvy (I think) these days, and really I should probably have split these into separate channels. Stay tuned for more ... I have to be careful because I want to avoid breaking apps, which is my main concern. |
I've elected the simple approach -- HasPendingEvent() bool -- it just returns true if len(s.evch) > 0 |
Background
Looking at the demo application, a main loop is expected to look like this:
The Problem
Now, let's say you get three events in sequence. With this pattern what will happen is:
Wish
What I would like to be able to do instead (in my case to get mouse scrolling to feel smoother) is:
Not sure what the best API would be here. Maybe this?
Or maybe this?
Either of these would require minimal changes to any app to get this performance improvement.
The text was updated successfully, but these errors were encountered: