From 0009e31bd3eafc7d2be1439597df118d9c24c071 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 2 Mar 2023 22:35:32 +0000 Subject: [PATCH] heavy webworker load can park the main thread of a background chrome tab for 10sec; piggyback some pokes off postmessage --- copyparty/web/up2k.js | 13 +++++++++++-- copyparty/web/util.js | 5 +++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index 89b1c993..96651460 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -114,10 +114,10 @@ function up2k_flagbus() { do_take(now); return; } - if (flag.owner && now - flag.owner[1] > 5000) { + if (flag.owner && now - flag.owner[1] > 12000) { flag.owner = null; } - if (flag.wants && now - flag.wants[1] > 5000) { + if (flag.wants && now - flag.wants[1] > 12000) { flag.wants = null; } if (!flag.owner && !flag.wants) { @@ -772,6 +772,7 @@ function fsearch_explain(n) { function up2k_init(subtle) { var r = { + "tact": Date.now(), "init_deps": init_deps, "set_fsearch": set_fsearch, "gotallfiles": [gotallfiles] // hooks @@ -1647,8 +1648,14 @@ function up2k_init(subtle) { running = true; while (true) { var now = Date.now(), + blocktime = now - r.tact, is_busy = st.car < st.files.length; + if (blocktime > 2500) + console.log('main thread blocked for ' + blocktime); + + r.tact = now; + if (was_busy && !is_busy) { for (var a = 0; a < st.files.length; a++) { var t = st.files[a]; @@ -2043,6 +2050,8 @@ function up2k_init(subtle) { nbusy++; reading++; nchunk++; + if (Date.now() - up2k.tact > 1500) + tasker(); } function onmsg(d) { diff --git a/copyparty/web/util.js b/copyparty/web/util.js index 3cae49ef..c6103459 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -112,12 +112,13 @@ if ((document.location + '').indexOf(',rej,') + 1) try { console.hist = []; + var CMAXHIST = 100; var hook = function (t) { var orig = console[t].bind(console), cfun = function () { console.hist.push(Date.now() + ' ' + t + ': ' + Array.from(arguments).join(', ')); - if (console.hist.length > 100) - console.hist = console.hist.slice(50); + if (console.hist.length > CMAXHIST) + console.hist = console.hist.slice(CMAXHIST / 2); orig.apply(console, arguments); };