perf(desktop): cut startup log-directory scans from six to four - #605
Open
simpleqt wants to merge 1 commit into
Open
perf(desktop): cut startup log-directory scans from six to four#605simpleqt wants to merge 1 commit into
simpleqt wants to merge 1 commit into
Conversation
Boot constructs LogFileSink, calls enforceDirectoryCap() and purgeOlderThan(7), then writeHeader(); every ownedFiles() pass is a full readdirSync plus one lstatSync per owned log. That sequence used to walk the directory six times (constructor measure, cap, purge x2, and rollDate's per-channel loadState x2), reported in anywhere-labs#584. - rollDate(): fuse the two per-channel loadState scans into one ownedFiles() pass; per-entry matching logic is unchanged, including the equal-segment readdir-order tie behavior. - purgeOlderThan(): track surviving bytes during the deletion loop instead of re-measuring the directory afterwards; locked old files still count, so the accounting matches the previous re-scan. appendFileSync-per-line stays: closing after every append is the deliberate crash-safety tradeoff noted in the code. Boot now scans four times, and each daily date rollover scans once instead of twice. Fixes anywhere-labs#584 (startup directory-scan part; the per-line sync write is intentional and left as is) Verified: vitest tests/log-files.spec.ts 15/15 (two new regression tests: dual-channel segment resume, and cap-then-purge boot sequence), full workspace suite 812 passed / 4 skipped, tsc typecheck clean, bilingual/architecture/layout gates green.
simpleqt
force-pushed
the
perf/log-sink-boot-directory-scans
branch
from
August 25, 2026 08:43
8b815d7 to
2547f13
Compare
9 tasks
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.
Fixes the startup directory-scan part of #584.
What
Every
LogFileSinkstartup walks the log directory viaownedFiles()(a fullreaddirSyncplus onelstatSyncper owned log). The boot sequence inmain.ts(new LogFileSink→enforceDirectoryCap()→purgeOlderThan(7)→writeHeader()) used to trigger six such walks:measureDirectoryBytes()enforceDirectoryCap()ownedFiles()purgeOlderThanownedFiles()purgeOlderThanclosingmeasureDirectoryBytes()rollDate→loadState(all)rollDate→loadState(error)(#584 counted ~5; the per-channel
loadStatepair makes it six.)Change
rollDate()fuses the two per-channelloadStatescans into oneownedFiles()pass (resumeSegmentStatehelper keeps the per-entry matching logic byte-for-byte, including the equal-segment readdir-order tie behavior).purgeOlderThan()tracks surviving bytes inside the deletion loop instead of re-measuring the directory afterwards; locked old files still count toward the total, matching what the previous re-scan would have produced.Boot now scans four times, and each daily date rollover scans once instead of twice. The per-line
appendFileSyncis untouched — closing after every append is the deliberate crash-safety tradeoff already documented in the code.Verification
vitest run tests/log-files.spec.ts— 15/15, including two new regression tests:cap → purge → writeHeadersequence while old files are removedtsctypecheck (all five tsconfigs) — clean