Closed ces42 closed 11 months ago
@ces42 I apologize for the delayed review of the pull request. Thank you for tuning the performance. I have made some comments.
Hi! I'm traveling right now so I probably won't have time to look at this until next week. I have made some more changes (locally) and I split the ones here into three separate branches, maybe that will make reviewing easier.
This addresses part of https://github.com/iberianpig/fusuma/issues/295 . It fixes the inefficiency in https://github.com/iberianpig/fusuma/blob/b68ab60335260dc32bfb3748c0bf65f9dc6d9dad/lib/fusuma/plugin/buffers/gesture_buffer.rb#L99-L107
.reverse.find
has bad runtime because it creates a reversed copy of the list (in linear time) and then iterates over it. But of course one should just iterate backwards over the list.Furthermore instead of searching the whole buffer at every call of
select_from_last_begin
we should just search all entries that have been added since the last call and if none of them are a "begin" we just return the same as last time. This is what the two new variables@mem_last_begin
and@mem_checked
are for. When I run fusuma, the "begin" event is always at index 0 because the buffer isclear
ed before the next gesture starts and there's always one more entry in@events
than in the last call. So this optimization is very efficient.Finally, if the last "begin" did happen at index 0 we can return
self
instead of returning an identical copy.possible problems that this could cause: Things will break if
@events
is modified in-place in any way other than appending events (e.g.pop()
)select_from_last_begin
returnsself
and that return value is modifiedprofiling I enabled the line profiler and ran
master
vs my fork while (3-finger) swiping from one end of my touchpad to the other end (separate swipes left, right, left, right, etc.) withtime exe/fusuma
current master:
this fork: