Skip to content

Commit

Permalink
avoid chrome webworker OOM bug; closes #124
Browse files Browse the repository at this point in the history
chrome (and chromium-based browsers) can OOM when:

* the OS is Windows, MacOS, or Android (but not Linux?)
* the website is hosted on a remote IP (not localhost)
* webworkers are used to read files

unfortunately this also applies to Android, which heavily relies
on webworkers to make read-speeds anywhere close to acceptable

as for android, there are diminishing returns with more than 4
webworkers (1=1x, 2=2.3x, 3=3.8x, 4=4.2x, 6=4.5x, 8=5.3x), and
limiting the number of workers to ensure at least one idle core
appears to sufficiently reduce the OOM probability

on desktop, webworkers are only necessary for hashwasm, so
limit the number of workers to 2 if crypto.subtle is available
and otherwise use the nproc-1 rule for hashwasm in workers

bug report: https://issues.chromium.org/issues/383568268
  • Loading branch information
9001 committed Dec 11, 2024
1 parent a49bf81 commit 24ce46b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ same order here too

* [Chrome issue 1352210](https://bugs.chromium.org/p/chromium/issues/detail?id=1352210) -- plaintext http may be faster at filehashing than https (but also extremely CPU-intensive)

* [Chrome issue 383568268](https://issues.chromium.org/issues/383568268) -- filereaders in webworkers can OOM / crash the browser-tab
* copyparty has a workaround which seems to work well enough

* [Firefox issue 1790500](https://bugzilla.mozilla.org/show_bug.cgi?id=1790500) -- entire browser can crash after uploading ~4000 small files

* Android: music playback randomly stops due to [battery usage settings](#fix-unreliable-playback-on-android)
Expand Down
10 changes: 9 additions & 1 deletion copyparty/web/up2k.js
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,15 @@ function up2k_init(subtle) {
draw_each = good_files.length < 50;

if (WebAssembly && !hws.length) {
for (var a = 0; a < Math.min(navigator.hardwareConcurrency || 4, 16); a++)
var nw = Math.min(navigator.hardwareConcurrency || 4, 16);

if (CHROME) {
// chrome-bug 383568268 // #124
nw = Math.max(1, (nw > 4 ? 4 : (nw - 1)));
nw = (subtle && !MOBILE && nw > 2) ? 2 : nw;
}

for (var a = 0; a < nw; a++)
hws.push(new Worker(SR + '/.cpr/w.hash.js?_=' + TS));

if (!subtle)
Expand Down

0 comments on commit 24ce46b

Please sign in to comment.