perf: async main-process file I/O and debounced log counter#36
Merged
Conversation
Convert fs:readText and fs:list IPC handlers from synchronous fs calls to async fs.promises so reading large logs or listing big folders no longer blocks the main process event loop. fs:list now stats entries concurrently via Promise.all. Return shapes are unchanged, so the renderer needs no updates. Debounce the LOG line/character counter (150ms) on the textarea input event to avoid re-splitting the whole buffer on every keystroke when editing very large pasted logs. Context switches (tab/language) still update the counter immediately.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Performance improvements with no behavior or API changes — purely internal. Three hotspots are addressed: blocking file I/O in the main process and an unthrottled counter in the renderer.
Changes
1. Non-blocking file read —
fs:readText(src/main/ipc.js)The viewer's file reader used synchronous
fs.statSync/fs.openSync/fs.readSync/fs.closeSync, reading up to 5 MB on the main thread. While a large LOG loads, the main process event loop is frozen, so every window and all IPC stall.fs.promises(fsp.stat,fsp.open,FileHandle.read,FileHandle.close).truncatedflag and the returned object shape are all unchanged.2. Non-blocking directory listing —
fs:list(src/main/ipc.js)The file-tree listing did a blocking
fs.statSyncper entry, serializing one syscall after another on large folders.fsp.readdir+fsp.stat.Promise.all, so listing a big folder no longer blocks the main process and finishes faster.3. Debounced LOG counter —
src/renderer/js/app.jsThe line/character counter ran on every
inputevent of the LOG textarea, re-splitting the entire buffer with a regex on each keystroke — noticeably laggy when editing or pasting very large logs.updateCounterSoon()(150 ms debounce) and wired it to the textareainputhandler.updateCounter()immediately, so the displayed count is always correct when the active LOG changes.Why
Compatibility / risk
Validation
test/selftest.test.js) covers i18n keys, highlight regex compilation and duplicate ids; it does not touch these code paths, so its behavior is unaffected. Please runnpm testin CI / a Node environment to confirm (Node was not available in the dev environment used here).Files changed
src/main/ipc.js— asyncfs:readTextandfs:listsrc/renderer/js/app.js— debounced counter