From 59c10274b402c7fcca5d2765cb38e535e17907c2 Mon Sep 17 00:00:00 2001 From: "Avi Halachmi (:avih)" Date: Fri, 16 Jul 2021 10:37:41 +0300 Subject: stats.lua: scroll: allow throttling page-rebuild (no-op) Typically the current page is rebuilt and rendered once per second, howeve, scrolling can invoke the rebuild function very frequently, even at a rate which is too fast for the rebuild function to keep up. This can result in high CPU usage and input lag. This commit adds an argument to the page-rebuild function, letting it know whether or not it's called following a scroll keypress, thus allowing it to cache intermediate data so that it doesn't have to re-calculate the whole page from scratch. This additional argument is unused currently, but it could be useful for the internal performance page - which can be relatively heavy. --- player/lua/stats.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/player/lua/stats.lua b/player/lua/stats.lua index 653a367b77..93dc453da4 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -838,11 +838,12 @@ local function record_data(skip) end -- Call the function for `page` and print it to OSD -local function print_page(page) +local function print_page(page, after_scroll) if o.persistent_overlay then - mp.set_osd_ass(0, 0, pages[page].f()) + mp.set_osd_ass(0, 0, pages[page].f(after_scroll)) else - mp.osd_message(pages[page].f(), display_timer.oneshot and o.duration or o.redraw_delay + 1) + mp.osd_message(pages[page].f(after_scroll), + display_timer.oneshot and o.duration or o.redraw_delay + 1) end end @@ -854,7 +855,7 @@ end local function scroll_delta(d) if display_timer.oneshot then display_timer:kill() ; display_timer:resume() end pages[curr_page].offset = (pages[curr_page].offset or 1) + d - print_page(curr_page) + print_page(curr_page, true) end local function scroll_up() scroll_delta(-o.scroll_lines) end local function scroll_down() scroll_delta(o.scroll_lines) end -- cgit v1.2.3