Repository navigation
perf: run a long note's first word count in slices (huge idle-lag 380 → 17 ms) - #324
Merged
Merged
Conversation
The first count of a note has no cached block counts and ran as one task right after the first pause in typing: about 380 ms on the 8 MB document. DocumentCounter does the same counting in 8 ms slices, keeps its place, and reports once every block has a count. The bench's idle-lag probe also counted the open's own long tasks from its buffered observer; it now counts only tasks reaching into the window.
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.
What
The longest stall after typing stops on a long note was the first word count. Block counts are cached, but the first count has nothing cached. It is scheduled 400 ms after mount, typing keeps deferring it, and so it ran as one ~380 ms task (all 43,970 blocks of the 8 MB doc) right after the first pause. Once it has run, a pause stalls nothing over 30 ms.
DocumentCounter(word-count.ts): a resumable count. It counts uncached blocks until told time is up (always at least one block per call), resumes on the same doc, starts over on a changed doc (the cache keeps what was already counted), and returns the same result ascountDocumentWords.NotoEditor.reportCountruns it in 8 ms slices withsetTimeout(0)between them. The existing count timer covers the continuation, so a new edit ordestroycancels it.Measurement fix
run-noto.mjs's idle-lag probe uses a buffered Long Tasks observer. The buffer held the open's own 450–650 ms mount task, so most idle-lag numbers reported until now were the open, not idle work. The probe now counts only long tasks that reach into the observed window.Numbers (packaged, Linux x64, Xvfb, BENCH_RUNS=5, interleaved ×2, corrected probe)
Huge word count: identical (1,401,569 words). It now appears ~0.1 s later. Open, typing and save are unchanged within noise.
Tests: new
DocumentCountercases (every slice size gives the whole-document count; a changed doc restarts without re-measuring kept blocks). Typecheck and full unit suite are green.