From 233952af8ffb40ca1186cf67ff28e5a16ec0aa81 Mon Sep 17 00:00:00 2001 From: Administrator Date: Sun, 21 Jun 2026 02:29:59 +0200 Subject: [PATCH] =?UTF-8?q?perf(doodstream):=20gate=20per-upload=20=5Fdebu?= =?UTF-8?q?gLog=20behind=20logVerbose=20(default=20off)=20=E2=80=94=20drop?= =?UTF-8?q?=20~8-15=20sync=20fs=20syscalls/upload=20off=20the=20main=20loo?= =?UTF-8?q?p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit doodstream-upload.js's _debugLog ran with NO verbose gate: every call did a synchronous statSync (via maybeRotateLogFile) + appendFileSync directly on the main-process event loop, ~8-15x per upload (server probe, response, redirect, result page, filecode parse, hidden fields, submit/follow, plus retry branches). DoodstreamUploader runs in the main process, so each pair of sync fs syscalls blocked the event loop while uploading — delaying IPC, upload-progress-batch forwarding, tray-tooltip and webhook handling for every other concurrent upload. A constant per-upload main-thread tax (not history-scaling), surfaced by the session-wide lag audit and confirmed as the one finding that bites in the real upload scenario. Fix: gate _debugLog behind the existing globalSettings.logVerbose setting (default false), exactly mirroring main.js logDebug/_logVerbose. A module-level _debugVerbose flag + setDebugVerbose() setter, an early-return at the top of _debugLog, and one wire at main.js's single setLogVerbose chokepoint (covers boot + save-config + the verbose toggle). When verbose is off the doodstream trace simply isn't written — same contract as the main debug.log — and the per-upload sync fs disappears. When a doodstream issue needs tracing, enabling verbose restores the full trace. The config-store audit findings (load() history-clone cost, per-write history serialize) are real but scale only with history size — tens of microseconds at this user's 8-batch config, and the safe fix is risky persistence surgery on credential-bearing code for a latent micro-cost; deferred and documented in tasks/todo.md rather than shipped. 397/397 tests pass, eslint clean, gate wiring verified (shared module instance, default-off, toggles). Co-Authored-By: Claude Opus 4.8 (1M context) --- lib/doodstream-upload.js | 5 +++++ main.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/doodstream-upload.js b/lib/doodstream-upload.js index bb40c3a..02fcaaa 100644 --- a/lib/doodstream-upload.js +++ b/lib/doodstream-upload.js @@ -27,7 +27,11 @@ function _doodstreamLogPath() { return path.join(__dirname, '..', 'doodstream-debug.log'); } +let _debugVerbose = false; +function setDebugVerbose(v) { _debugVerbose = !!v; } + function _debugLog(msg) { + if (!_debugVerbose) return; try { const logPath = _doodstreamLogPath(); maybeRotateLogFile(logPath, _DOODSTREAM_LOG_MAX_BYTES, _DOODSTREAM_LOG_MAX_BACKUPS); @@ -698,3 +702,4 @@ class DoodstreamUploader { } module.exports = DoodstreamUploader; +module.exports.setDebugVerbose = setDebugVerbose; diff --git a/main.js b/main.js index 4135528..7c7c938 100644 --- a/main.js +++ b/main.js @@ -139,7 +139,7 @@ function debugLog(msg) { } let _logVerbose = false; -function setLogVerbose(v) { _logVerbose = !!v; } +function setLogVerbose(v) { _logVerbose = !!v; try { require('./lib/doodstream-upload').setDebugVerbose(_logVerbose); } catch {} } function _ctxTag(ctx) { if (!ctx || typeof ctx !== 'object') return ''; const tags = [];