diff --git a/README.md b/README.md index dd6b6a8a..58f6dbe3 100644 --- a/README.md +++ b/README.md @@ -2518,6 +2518,11 @@ below are some tweaks roughly ordered by usefulness: when uploading files, +* when uploading from very fast storage (NVMe SSD) with chrome/firefox, enable `[wasm]` in the `[⚙️] settings` tab to more effectively use all CPU-cores for hashing + * don't do this on Safari (runs faster without) + * don't do this on older browsers; likely to provoke browser-bugs (browser eats all RAM and crashes) + * can be made default-enabled serverside with `--nosubtle 137` (chrome v137+) or `--nosubtle 2` (chrome+firefox) + * chrome is recommended (unfortunately), at least compared to firefox: * up to 90% faster when hashing, especially on SSDs * up to 40% faster when uploading over extremely fast internets diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 9b42a309..8f67f282 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -1028,6 +1028,7 @@ def add_upload(ap): ap2.add_argument("--df", metavar="GiB", type=u, default="0", help="ensure \033[33mGiB\033[0m free disk space by rejecting upload requests; assumes gigabytes unless a unit suffix is given: [\033[32m256m\033[0m], [\033[32m4\033[0m], [\033[32m2T\033[0m] (volflag=df)") ap2.add_argument("--sparse", metavar="MiB", type=int, default=4, help="windows-only: minimum size of incoming uploads through up2k before they are made into sparse files") ap2.add_argument("--turbo", metavar="LVL", type=int, default=0, help="configure turbo-mode in up2k client; [\033[32m-1\033[0m] = forbidden/always-off, [\033[32m0\033[0m] = default-off and warn if enabled, [\033[32m1\033[0m] = default-off, [\033[32m2\033[0m] = on, [\033[32m3\033[0m] = on and disable datecheck") + ap2.add_argument("--nosubtle", metavar="N", type=int, default=0, help="when to use a wasm-hasher instead of the browser's builtin; faster on chrome, but buggy in older chrome versions. [\033[32m0\033[0m] = only when necessary (non-https), [\033[32m1\033[0m] = always (all browsers), [\033[32m2\033[0m] = always on chrome/firefox, [\033[32m3\033[0m] = always on chrome, [\033[32mN\033[0m] = chrome-version N and newer (recommendation: 137)") ap2.add_argument("--u2j", metavar="JOBS", type=int, default=2, help="web-client: number of file chunks to upload in parallel; 1 or 2 is good when latency is low (same-country), 2~4 for android-clients, 2~6 for cross-atlantic. Max is 6 in most browsers. Big values increase network-speed but may reduce HDD-speed") ap2.add_argument("--u2sz", metavar="N,N,N", type=u, default="1,64,96", help="web-client: default upload chunksize (MiB); sets \033[33mmin,default,max\033[0m in the settings gui. Each HTTP POST will aim for \033[33mdefault\033[0m, and never exceed \033[33mmax\033[0m. Cloudflare max is 96. Big values are good for cross-atlantic but may increase HDD fragmentation on some FS. Disable this optimization with [\033[32m1,1,1\033[0m]") ap2.add_argument("--u2ow", metavar="NUM", type=int, default=0, help="web-client: default setting for when to replace/overwrite existing files; [\033[32m0\033[0m]=never, [\033[32m1\033[0m]=if-client-newer, [\033[32m2\033[0m]=always (volflag=u2ow)") diff --git a/copyparty/authsrv.py b/copyparty/authsrv.py index 92fccf75..25e3ef5d 100644 --- a/copyparty/authsrv.py +++ b/copyparty/authsrv.py @@ -2563,6 +2563,7 @@ class AuthSrv(object): "idxh": int(self.args.ih), "themes": self.args.themes, "turbolvl": self.args.turbo, + "nosubtle": self.args.nosubtle, "u2j": self.args.u2j, "u2sz": self.args.u2sz, "u2ts": vf["u2ts"], diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 6cb85b91..2df78141 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -249,6 +249,8 @@ var Ls = { "cut_mt": "use multithreading to accelerate file hashing$N$Nthis uses web-workers and requires$Nmore RAM (up to 512 MiB extra)$N$Nmakes https 30% faster, http 4.5x faster\">mt", + "cut_wasm": "use wasm instead of the browser's built-in hasher; improves speed on chrome-based browsers but increases CPU load, and many older versions of chrome have bugs which makes the browser consume all RAM and crash if this is enabled\">wasm", + "cft_text": "favicon text (blank and refresh to disable)", "cft_fg": "foreground color", "cft_bg": "background color", @@ -864,6 +866,8 @@ var Ls = { "cut_mt": "raskere befaring ved å bruke hele CPU'en$N$Ndenne funksjonen anvender web-workers$Nog krever mer RAM (opptil 512 MiB ekstra)$N$Ngjør https 30% raskere, http 4.5x raskere\">mt", + "cut_wasm": "bruk wasm istedenfor nettleserens sha512-funksjon; gir bedre ytelse på chrome-baserte nettlesere, men bruker mere CPU, og eldre versjoner av chrome tåler det ikke (spiser opp all RAM og krasjer)\">wasm", + "cft_text": "ikontekst (blank ut og last siden på nytt for å deaktivere)", "cft_fg": "farge", "cft_bg": "bakgrunnsfarge", @@ -1479,6 +1483,8 @@ var Ls = { "cut_mt": "使用多线程加速文件哈希$N$N这使用 Web Worker 并且需要更多内存(额外最多 512 MiB)$N$N这使得 https 快 30%,http 快 4.5 倍\">mt", + "cut_wasm": "使用基于 WASM 的哈希计算器代替浏览器内置的哈希功能;这可以提升在基于 Chrome 的浏览器上的速度,但会增加 CPU 使用率,而且许多旧版本的 Chrome 存在漏洞,启用此功能会导致浏览器占用所有内存并崩溃。\">wasm", //m + "cft_text": "网站图标文本(为空并刷新以禁用)", "cft_fg": "前景色", "cft_bg": "背景色", @@ -2090,6 +2096,7 @@ ebi('op_cfg').innerHTML = ( ' ' + diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index 733672e5..8a8f393d 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -1,6 +1,18 @@ "use strict"; +(function () { + var x = sread('nosubtle'); + if (x === '0' || x === '1') + nosubtle = parseInt(x); + if ((nosubtle > 1 && !CHROME && !FIREFOX) || + (nosubtle > 2 && !CHROME) || + (CHROME && nosubtle > VCHROME) || + !WebAssembly) + nosubtle = 0; +})(); + + function goto_up2k() { if (up2k === false) return goto('bup'); @@ -23,7 +35,7 @@ var up2k = null, m = 'will use ' + sha_js + ' instead of native sha512 due to'; try { - if (sread('nosubtle') || window.nosubtle) + if (nosubtle) throw 'chickenbit'; var cf = crypto.subtle || crypto.webkitSubtle; cf.digest('SHA-512', new Uint8Array(1)).then( @@ -825,7 +837,7 @@ function up2k_init(subtle) { } qsr('#u2depmsg'); var o = mknod('div', 'u2depmsg'); - o.innerHTML = m; + o.innerHTML = nosubtle ? '' : m; ebi('u2foot').appendChild(o); } loading_deps = true; @@ -881,7 +893,8 @@ function up2k_init(subtle) { bcfg_bind(uc, 'turbo', 'u2turbo', turbolvl > 1, draw_turbo); bcfg_bind(uc, 'datechk', 'u2tdate', turbolvl < 3, null); bcfg_bind(uc, 'az', 'u2sort', u2sort.indexOf('n') + 1, set_u2sort); - bcfg_bind(uc, 'hashw', 'hashw', !!WebAssembly && !(CHROME && MOBILE) && (!subtle || !CHROME), set_hashw); + bcfg_bind(uc, 'hashw', 'hashw', !!WebAssembly && !(CHROME && MOBILE) && (!subtle || !CHROME || VCHROME > 136), set_hashw); + bcfg_bind(uc, 'hwasm', 'nosubtle', nosubtle, set_nosubtle); bcfg_bind(uc, 'upnag', 'upnag', false, set_upnag); bcfg_bind(uc, 'upsfx', 'upsfx', false, set_upsfx); @@ -1442,6 +1455,7 @@ function up2k_init(subtle) { if (CHROME) { // chrome-bug 383568268 // #124 nw = Math.max(1, (nw > 4 ? 4 : (nw - 1))); + if (VCHROME < 137) nw = (subtle && !MOBILE && nw > 2) ? 2 : nw; } @@ -3291,6 +3305,12 @@ function up2k_init(subtle) { } } + function set_nosubtle(v) { + if (!WebAssembly) + return toast.err(10, L.u_nowork); + modal.confirm(L.lang_set, location.reload.bind(location), null); + } + function set_upnag(en) { function nopenag() { bcfg_set('upnag', uc.upnag = false); diff --git a/copyparty/web/util.js b/copyparty/web/util.js index 02423036..0ee7c637 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -69,7 +69,7 @@ try { CHROME = navigator.userAgentData.brands.find(function (d) { return d.brand == 'Chromium' }); if (CHROME) - VCHROME = CHROME.version; + VCHROME = parseInt(CHROME.version); else VCHROME = 0; diff --git a/scripts/tl.js b/scripts/tl.js index 8397085c..3069099c 100644 --- a/scripts/tl.js +++ b/scripts/tl.js @@ -335,6 +335,8 @@ var tl_browser = { "cut_mt": "use multithreading to accelerate file hashing$N$Nthis uses web-workers and requires$Nmore RAM (up to 512 MiB extra)$N$Nmakes https 30% faster, http 4.5x faster\">mt", + "cut_wasm": "use wasm instead of the browser's built-in hasher; improves speed on chrome-based browsers but increases CPU load, and many older versions of chrome have bugs which makes the browser consume all RAM and crash if this is enabled\">wasm", + "cft_text": "favicon text (blank and refresh to disable)", "cft_fg": "foreground color", "cft_bg": "background color", diff --git a/tests/util.py b/tests/util.py index ce6261ee..891036e5 100644 --- a/tests/util.py +++ b/tests/util.py @@ -158,7 +158,7 @@ class Cfg(Namespace): ex = "au_vol dl_list mtab_age reg_cap s_thead s_tbody th_convt ups_who zip_who" ka.update(**{k: 9 for k in ex.split()}) - ex = "db_act forget_ip k304 loris no304 re_maxage rproxy rsp_jtr rsp_slp s_wr_slp snap_wri theme themes turbo u2ow zipmaxn zipmaxs" + ex = "db_act forget_ip k304 loris no304 nosubtle re_maxage rproxy rsp_jtr rsp_slp s_wr_slp snap_wri theme themes turbo u2ow zipmaxn zipmaxs" ka.update(**{k: 0 for k in ex.split()}) ex = "ah_alg bname chpw_db doctitle df exit favico idp_h_usr ipa html_head lg_sba lg_sbf log_fk md_sba md_sbf name og_desc og_site og_th og_title og_title_a og_title_v og_title_i shr tcolor textfiles unlist vname xff_src zipmaxt R RS SR"