From 7d78c9a6a491b17d879400fe79fb6c0d75a1add8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Sun, 26 Jan 2025 14:13:55 +0100 Subject: [PATCH] scroll: fix high cpu usage #996 --- layouts/partials/version.txt | 2 +- static/js/theme.js | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/layouts/partials/version.txt b/layouts/partials/version.txt index 0162ff1111..a26cdea556 100644 --- a/layouts/partials/version.txt +++ b/layouts/partials/version.txt @@ -1 +1 @@ -7.3.1+4f182a115b0a3a6d4b6b2ba46abe3c4e71cfda5c \ No newline at end of file +7.3.1+c4a8c278be4013f283872b4cbb88e4baa19b2988 \ No newline at end of file diff --git a/static/js/theme.js b/static/js/theme.js index e3eb06d132..130d0c6af6 100644 --- a/static/js/theme.js +++ b/static/js/theme.js @@ -62,6 +62,17 @@ function adjustContentWidth() { elc.style[dir_padding_end] = '' + end + 'px'; } +function throttle(func, limit) { + let inThrottle; + return function (...args) { + if (!inThrottle) { + func.apply(this, args); + inThrottle = true; + setTimeout(() => (inThrottle = false), limit); + } + }; +} + function fixCodeTabs() { /* if only a single code block is contained in the tab and no style was selected, treat it like style=code */ var codeTabContents = Array.from(document.querySelectorAll('.tab-content.tab-panel-style')).filter(function (tabContent) { @@ -1311,7 +1322,8 @@ function initScrollPositionSaver() { elc.addEventListener('scroll', function (event) { if (!ticking) { window.requestAnimationFrame(function () { - savePosition(); + // #996 GC is so damn slow that we need further throttling + throttle(savePosition, 250); ticking = false; }); ticking = true;