perf: optimize snapshot job handling
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
requestAnimationFrameafter 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
setTimeoutwithrequestIdleCallbackfor 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
β οΈ 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
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 |
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.
βοΈ 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.
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%) |
@Saul-Mirone @fourdim refactored under new RFC, PTAL.
@Saul-Mirone What about your use case in https://github.com/toeverything/blocksuite/pull/7796? Is this PR suitable?
@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.
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.