Skip to content

Conversation

@ad1992
Copy link
Member

@ad1992 ad1992 commented Jul 22, 2024

Try here - https://excalidraw-git-aakansha-fix-labeled-arrow-perf-excalidraw.vercel.app/#json=TVewArjSDX8Eh9Tsquq33,7IbL43nXlxrvuVOB0x6Xnw

for #8257

Since we were creating a temp canvas to make sure that the bounding box of label is computed correctly when arrow is rotated since we needed to clear that area in label and this was happening for every render irrespective of whether the arrow was updated and hence slowing down the whole app for large number of labeled arrows.

Now I am caching the canvas for bound text elements along with the elementWithCanvasCache, significantly improving performance.
However, for rotation we still need to compute the bounding box on the fly hence I am bursting the cache for rotation. We can improve this further later

There is also one more issue with rotation which is in production as well - Try updating text in rotated arrow and text position gets updated, I will fix this in another PR.

perf-arrow.mp4

@vercel
Copy link

vercel bot commented Jul 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
excalidraw ✅ Ready (Inspect) Visit Preview Jul 22, 2024 8:03pm
excalidraw-package-example ✅ Ready (Inspect) Visit Preview Jul 22, 2024 8:03pm
excalidraw-package-example-with-nextjs ✅ Ready (Inspect) Visit Preview Jul 22, 2024 8:03pm
1 Skipped Deployment
Name Status Preview Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview Jul 22, 2024 8:03pm

@github-actions
Copy link

github-actions bot commented Jul 22, 2024

Coverage Report

Status Category Percentage Covered / Total
🔴 Lines 66.18% (🎯 70%) 53506 / 80839
🔴 Statements 66.18% (🎯 70%) 53506 / 80839
🔴 Functions 67.32% (🎯 68%) 1613 / 2396
🟢 Branches 80.86% (🎯 70%) 6526 / 8070
File Coverage
File Stmts % Branch % Funcs % Lines Uncovered Lines
Changed Files
packages/excalidraw/renderer/renderElement.ts 84.09% 76.86% 100% 84.09% 86-88, 110-111, 171-172, 176-177, 235-236, 350, 396-397, 410-427, 438-441, 455, 478-479, 481-482, 503, 608, 610-623, 685-687, 715-725, 766-774, 780-781, 785-848, 853-855, 908-910, 932, 935, 962-963
Generated in workflow #2825

@ad1992
Copy link
Member Author

ad1992 commented Jul 22, 2024

@dwelle @zsviczian this PR should be good to go

@zsviczian
Copy link
Collaborator

Looks good to me!
With my rudimentary testing I can see an at least 2x performance improvement 🎉🙏

zsviczian added a commit to zsviczian/excalidraw that referenced this pull request Jul 22, 2024
@dwelle
Copy link
Member

dwelle commented Jul 22, 2024

I've pushed a tweak to cache and predicate the cache busting on element.angle instead of appState.isRotating. This has 2 benefits:

  • more robust since appState.rotating is local-client only.
  • (drastically) improves performance when rotating unrelated shapes and there are lots of labeled arrows on canvas.

Otherwise we're good to go, thanks @ad1992!

@ad1992
Copy link
Member Author

ad1992 commented Jul 23, 2024

I've pushed a tweak to cache and predicate the cache busting on element.angle instead of appState.isRotating. This has 2 benefits:

  • more robust since appState.rotating is local-client only.
  • (drastically) improves performance when rotating unrelated shapes and there are lots of labeled arrows on canvas.

Otherwise we're good to go, thanks @ad1992!

Nice, thanks @dwelle!

@ad1992
Copy link
Member Author

ad1992 commented Jul 23, 2024

Looks good to me! With my rudimentary testing I can see an at least 2x performance improvement 🎉🙏

Awesome ✨

@ad1992 ad1992 merged commit bd7b778 into master Jul 23, 2024
@ad1992 ad1992 deleted the aakansha/fix-labeled-arrow-perf branch July 23, 2024 05:47
@helloankit
Copy link

Amazing!

Jauhen pushed a commit to Jauhen/excalidraw that referenced this pull request Nov 7, 2024
* perf: cache the temp canvas created for labeled arrows

* use allEleemntsMap so bound text element can be retrieved when editing

* remove logs

* fix rotation

* pass isRotating

* feat: cache `element.angle` instead of relying on `appState.isRotating`

---------

Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants