-
-
Notifications
You must be signed in to change notification settings - Fork 737
[Performance] Debounce word counting #5952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
|
You guys are all writing too large documents. (/s) Will have a look later! |
|
Trust me, I wish I wasnt! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, I didn't submit my review last week, but somehow GitHub seems to have remembered all my comments…?!
|
|
||
| if (update.selectionSet) { | ||
| this.emit('cursorActivity') | ||
| this.emit('docUpdate') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this also now need to be emitted from the update branch a few lines above?
| for (const effect of transaction.effects) { | ||
| // Listen for word count updates | ||
| if (effect.is(updateWordCountEffect)) { | ||
| this.emit('docUpdate') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mh, I'm wondering if docUpdate semantically correctly describes when and how this event is being emitted ...?
| // return true. | ||
| if (!transaction.docChanged) { | ||
| return value | ||
| for (let e of transaction.effects) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| for (let e of transaction.effects) { | |
| for (const e of transaction.effects) { |
|
|
||
| export const countPlugin = ViewPlugin.fromClass(class { | ||
| private timeout: number | null = null | ||
| private delay = 750 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this as a constant to the top of the file so that we can adjust this if necessary (e.g., something like const WORD_COUNT_DELAY = 750)
Description
This PR implements a debounced word counting plugin to improve typing performance.
Changes
The word count computation was moved to a
ViewPluginso that it can be debounced usingsetTimeout(). It uses aStateEffectto update the existingcountFieldvalue.Event listeners were added for the new
updateWordCountEffectso that the UI shows updated counts when they arrive rather than waiting for cursor activity.Additional information
Currently, word counts are recomputed every keypress. In larger documents (>50,000 words) this starts to add a small but noticeable, and increasing, delay. By debouncing the counting, typing performance is dramatically improved in large documents.
Word counts are no longer live, however, they are updated the moment the transaction is dispatched.
Tested on: