scroll: fix high cpu usage #996

This commit is contained in:
Sören Weber 2025-01-26 14:13:55 +01:00
parent c4a8c278be
commit 7d78c9a6a4
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
2 changed files with 14 additions and 2 deletions

View file

@ -1 +1 @@
7.3.1+4f182a115b0a3a6d4b6b2ba46abe3c4e71cfda5c 7.3.1+c4a8c278be4013f283872b4cbb88e4baa19b2988

View file

@ -62,6 +62,17 @@ function adjustContentWidth() {
elc.style[dir_padding_end] = '' + end + 'px'; 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() { function fixCodeTabs() {
/* if only a single code block is contained in the tab and no style was selected, treat it like style=code */ /* 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) { 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) { elc.addEventListener('scroll', function (event) {
if (!ticking) { if (!ticking) {
window.requestAnimationFrame(function () { window.requestAnimationFrame(function () {
savePosition(); // #996 GC is so damn slow that we need further throttling
throttle(savePosition, 250);
ticking = false; ticking = false;
}); });
ticking = true; ticking = true;