Skip to content
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

perf(editor): reduce frequency of native selection sync #9509

Draft
wants to merge 5 commits into
base: canary
Choose a base branch
from

Conversation

doodlewind
Copy link
Member

@doodlewind doodlewind commented Jan 3, 2025

Currently, the native selection sync logic is costly in large docs. While there is already a throttle(10ms) in place, the actual DOM querying cost can take several hundred milliseconds, leading to multiple redundant executions queuing up and high CPU usage.

This PR implements a custom serialThrottle that ensures only one execution runs at a time and processes only the latest selection state once the previous execution completes. This eliminates redundant DOM queries without affecting the selection sync accuracy, effectively reducing CPU usage while maintaining UI responsiveness.

Tested using a markdown novel with ~20k words (100k characters).

moby-dick-chap1-10.md

Before:

image

After:

image

@doodlewind doodlewind requested a review from a team as a code owner January 3, 2025 09:31
@graphite-app graphite-app bot requested a review from forehalo January 3, 2025 09:31
Copy link

graphite-app bot commented Jan 3, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@github-actions github-actions bot added the test Related to test cases label Jan 3, 2025
Copy link

codecov bot commented Jan 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 52.89%. Comparing base (cfd64f1) to head (e0e3db7).
Report is 3 commits behind head on canary.

Additional details and impacted files
@@            Coverage Diff             @@
##           canary    #9509      +/-   ##
==========================================
- Coverage   52.91%   52.89%   -0.02%     
==========================================
  Files        2152     2151       -1     
  Lines       97039    97039              
  Branches    16161    16162       +1     
==========================================
- Hits        51350    51331      -19     
- Misses      44322    44340      +18     
- Partials     1367     1368       +1     
Flag Coverage Δ
server-test 78.07% <ø> (-0.07%) ⬇️
unittest 32.51% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@doodlewind doodlewind marked this pull request as draft January 3, 2025 10:15
@doodlewind doodlewind changed the title perf(editor): use serial throttle for native selection sync perf(editor): reduce frequency of native selection sync Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Related to test cases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant