blocksuite icon indicating copy to clipboard operation
blocksuite copied to clipboard

perf: optimize snapshot job handling

Open doodlewind opened this issue 1 year ago β€’ 5 comments

Close #8380

This PR significantly improves the performance of block import operations by addressing several inefficiencies in the current implementation:

  • Removed the need to wait for requestAnimationFrame after each block insertion (see #7796), which was causing significant slowdowns.
  • Fixed the batch mechanism (see #7790) that wasn't properly enabled, replacing serial execution with true parallel processing.
  • Instead of executing all remaining tasks at once after 100 items (still causing UI freezes), we now process tasks in consistent batches of 100 per tick.
  • Replaced setTimeout with requestIdleCallback for batch ticks, better utilizing idle browser time.

These optimizations result in much faster block imports while maintaining UI responsiveness. The new implementation processes 100 tasks per tick, striking a balance between speed and smooth user experience.

Tested using clipboard-test.md with 1000 line and 600 blocks:

Before (took ~10s to paste)

https://github.com/user-attachments/assets/3a6379c9-621e-490e-a79f-4377494d5915

After (instant response without blocking UI)

https://github.com/user-attachments/assets/dea7c1f9-a8c1-4926-92b7-f5cb40957fad

doodlewind avatar Sep 22 '24 03:09 doodlewind

⚠️ No Changeset found

Latest commit: 94bc96e0c2ab7c13fbfcc081805cdf181fea18c3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Sep 22 '24 03:09 changeset-bot[bot]

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
blocksuite βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Oct 14, 2024 8:08am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
blocksuite-docs ⬜️ Ignored (Inspect) Visit Preview Oct 14, 2024 8:08am

vercel[bot] avatar Sep 22 '24 03:09 vercel[bot]

Your org has enabled the Graphite merge queue for merging into master

Add the label β€œmerge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge.

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

graphite-app[bot] avatar Sep 22 '24 03:09 graphite-app[bot]

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 94bc96e0c2ab7c13fbfcc081805cdf181fea18c3. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

πŸ“‚ See all runs for this CI Pipeline Execution


βœ… Successfully ran 1 target

Sent with πŸ’Œ from NxCloud.

nx-cloud[bot] avatar Sep 22 '24 03:09 nx-cloud[bot]

size-limit report πŸ“¦

Path Size
@blocksuite/affine 13 B (0%)
@blocksuite/affine/effects 2.07 MB (+0.11% πŸ”Ί)
@blocksuite/affine/block-std 154.55 KB (+0.19% πŸ”Ί)
@blocksuite/affine/block-std/gfx 76.93 KB (0%)
@blocksuite/affine/global 13 B (0%)
@blocksuite/affine/global/utils 13.82 KB (0%)
@blocksuite/affine/global/env 210 B (-9.1% πŸ”½)
@blocksuite/affine/global/exceptions 552 B (0%)
@blocksuite/affine/global/di 1.65 KB (0%)
@blocksuite/affine/global/types 13 B (0%)
@blocksuite/affine/store 78.36 KB (+0.52% πŸ”Ί)
@blocksuite/affine/inline 31.37 KB (+0.12% πŸ”Ί)
@blocksuite/affine/inline/consts 51 B (0%)
@blocksuite/affine/inline/types 13 B (0%)
@blocksuite/affine/presets 1.86 MB (+0.02% πŸ”Ί)
@blocksuite/affine/blocks 1.94 MB (-0.08% πŸ”½)
@blocksuite/affine/blocks/schemas 87.25 KB (0%)

github-actions[bot] avatar Sep 22 '24 03:09 github-actions[bot]

@Saul-Mirone @fourdim refactored under new RFC, PTAL.

doodlewind avatar Oct 12 '24 10:10 doodlewind

@Saul-Mirone What about your use case in https://github.com/toeverything/blocksuite/pull/7796? Is this PR suitable?

fourdim avatar Oct 12 '24 13:10 fourdim

@Saul-Mirone What about your use case in #7796? Is this PR suitable?

I've did some tests and the implementation in this pr seems fast enough.

Saul-Mirone avatar Oct 14 '24 07:10 Saul-Mirone

Merge activity

  • Oct 14, 4:04 AM EDT: The merge label 'merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Oct 14, 4:04 AM EDT: A user added this pull request to the Graphite merge queue.
  • Oct 14, 4:09 AM EDT: A user merged this pull request with the Graphite merge queue.

doodlewind avatar Oct 14 '24 08:10 doodlewind