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

Move command type out of listeners to registerCommandListener #1551

Merged
merged 14 commits into from
Mar 25, 2022

Conversation

thegreatercurve
Copy link
Contributor

@thegreatercurve thegreatercurve commented Mar 24, 2022

Following on from #1412 and #1512, we're trying to store commands by their type, and then by their priority order. This should allow us call listeners less often, and removes the need for users to have to check types in callbacks. Plus it should allow us to more easily type the commands themselves.

This effectively changes how we store the command from the below:

Array<Set<(payload: any) => boolean>>

...

Map<string, Array<Set<(payload: any) => boolean>>> 

In terms of performance, I don't think we're taking much of a hit, especially since #1509.

I 6x throttled the CPU of Chrome, and compared the task times for typing characters compared to main, and they average around the same number of milliseconds.

I was also able to add console.startEnd and console.startEnd to the beginning and end of execCommand and the times for the function to run appear fairly consistent across this and main.

main

LexicalEditor.js? [sm]:491 execCommand: selectionChange: 2.4990234375 ms
LexicalEditor.js? [sm]:491 execCommand: selectionChange: 0.081787109375 ms
LexicalEditor.js? [sm]:491 execCommand: click: 0.018310546875 ms
LexicalEditor.js? [sm]:491 execCommand: selectionChange: 0.8232421875 ms
LexicalEditor.js? [sm]:491 execCommand: selectionChange: 0.054931640625 ms
LexicalEditor.js? [sm]:491 execCommand: insertText: 4.986083984375 ms
LexicalEditor.js? [sm]:491 execCommand: canUndo: 0.01806640625 ms
LexicalEditor.js? [sm]:491 execCommand: selectionChange: 1.47216796875 ms
LexicalEditor.js? [sm]:491 execCommand: selectionChange: 0.921875 ms
LexicalEditor.js? [sm]:491 execCommand: selectionChange: 0.8740234375 ms
LexicalEditor.js? [sm]:491 execCommand: selectionChange: 0.05908203125 ms
LexicalEditor.js? [sm]:491 execCommand: selectionChange: 0.06201171875 ms
LexicalEditor.js? [sm]:491 execCommand: canUndo: 0.0048828125 ms
LexicalEditor.js? [sm]:491 execCommand: selectionChange: 0.6357421875 ms
LexicalEditor.js? [sm]:491 execCommand: selectionChange: 0.602783203125 ms
LexicalEditor.js? [sm]:491 execCommand: selectionChange: 1.773681640625 ms
LexicalEditor.js? [sm]:491 execCommand: selectionChange: 0.05908203125 ms
LexicalEditor.js? [sm]:491 execCommand: selectionChange: 0.06689453125 ms
LexicalEditor.js? [sm]:491 execCommand: selectionChange: 1.1220703125 ms
LexicalEditor.js? [sm]:491 execCommand: selectionChange: 0.05908203125 ms
LexicalEditor.js? [sm]:491 execCommand: blur: 0.05419921875 ms
LexicalEditor.js? [sm]:491 execCommand: insertImage: 4.56787109375 ms
LexicalEditor.js? [sm]:491 execCommand: focus: 0.01904296875 ms
LexicalEditor.js? [sm]:491 execCommand: canUndo: 0.004150390625 ms
LexicalEditor.js? [sm]:491 execCommand: selectionChange: 1.068115234375 ms
LexicalEditor.js? [sm]:491 execCommand: blur: 1.15478515625 ms
LexicalEditor.js? [sm]:491 execCommand: insertTable: 8.030029296875 ms
LexicalEditor.js? [sm]:491 execCommand: focus: 0.01513671875 ms
LexicalEditor.js? [sm]:491 execCommand: canUndo: 0.00390625 ms
LexicalEditor.js? [sm]:491 execCommand: selectionChange: 0.731201171875 ms

branch

LexicalEditor.js? [sm]:507 execCommand: focus: 0.093017578125 ms
LexicalEditor.js? [sm]:507 execCommand: selectionChange: 1.68212890625 ms
LexicalEditor.js? [sm]:507 execCommand: selectionChange: 0.06396484375 ms
LexicalEditor.js? [sm]:507 execCommand: click: 0.475830078125 ms
LexicalEditor.js? [sm]:507 execCommand: selectionChange: 1.218017578125 ms
LexicalEditor.js? [sm]:507 execCommand: selectionChange: 1.10791015625 ms
LexicalEditor.js? [sm]:507 execCommand: insertText: 4.7412109375 ms
LexicalEditor.js? [sm]:507 execCommand: canUndo: 0.013916015625 ms
LexicalEditor.js? [sm]:507 execCommand: selectionChange: 1.672119140625 ms
LexicalEditor.js? [sm]:507 execCommand: selectionChange: 0.06298828125 ms
LexicalEditor.js? [sm]:507 execCommand: selectionChange: 1.130126953125 ms
LexicalEditor.js? [sm]:507 execCommand: selectionChange: 1.090087890625 ms
LexicalEditor.js? [sm]:507 execCommand: selectionChange: 1.138916015625 ms
LexicalEditor.js? [sm]:507 execCommand: canUndo: 0.004150390625 ms
LexicalEditor.js? [sm]:507 execCommand: selectionChange: 0.645751953125 ms
LexicalEditor.js? [sm]:507 execCommand: canUndo: 0.005126953125 ms
LexicalEditor.js? [sm]:507 execCommand: selectionChange: 0.054931640625 ms
LexicalEditor.js? [sm]:507 execCommand: selectionChange: 1.821044921875 ms
LexicalEditor.js? [sm]:507 execCommand: selectionChange: 0.052978515625 ms
LexicalEditor.js? [sm]:507 execCommand: selectionChange: 0.70703125 ms
LexicalEditor.js? [sm]:507 execCommand: selectionChange: 0.054931640625 ms
LexicalEditor.js? [sm]:507 execCommand: canUndo: 0.002685546875 ms
LexicalEditor.js? [sm]:507 execCommand: selectionChange: 0.052001953125 ms
LexicalEditor.js? [sm]:507 execCommand: blur: 0.797119140625 ms
LexicalEditor.js? [sm]:507 execCommand: insertImage: 4.267822265625 ms
LexicalEditor.js? [sm]:507 execCommand: focus: 0.006103515625 ms
LexicalEditor.js? [sm]:507 execCommand: canUndo: 0.0048828125 ms
LexicalEditor.js? [sm]:507 execCommand: selectionChange: 0.060302734375 ms
LexicalEditor.js? [sm]:507 execCommand: blur: 0.03515625 ms
LexicalEditor.js? [sm]:507 execCommand: insertTable: 8.25390625 ms
LexicalEditor.js? [sm]:507 execCommand: focus: 0.0068359375 ms
LexicalEditor.js? [sm]:507 execCommand: canUndo: 0.001953125 ms
LexicalEditor.js? [sm]:507 execCommand: selectionChange: 0.9169921875 ms

@vercel
Copy link

vercel bot commented Mar 24, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

lexical – ./packages/lexical-website

🔍 Inspect: https://vercel.com/fbopensource/lexical/2SkLtyig8xrcnasmZ4znRrjA82uL
✅ Preview: https://lexical-git-flow-type-move-into-args-fbopensource.vercel.app

lexical-playground – ./packages/lexical-playground

🔍 Inspect: https://vercel.com/fbopensource/lexical-playground/3mGotWvrgU7Q7p367sWbANdkyavM
✅ Preview: https://lexical-playground-git-flow-type-move-into-args-fbopensource.vercel.app

lexical-website-new – ./packages/lexical-website-new

🔍 Inspect: https://vercel.com/fbopensource/lexical-website-new/EGHR2sU2KtpGCG9hrQzQX6zn1CJi
✅ Preview: https://lexical-website-new-git-flow-type-move-into-args-fbopensource.vercel.app

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 24, 2022
@thegreatercurve thegreatercurve force-pushed the flow-type-move-into-args branch from fe53120 to 5b32429 Compare March 24, 2022 21:18
@thegreatercurve thegreatercurve force-pushed the flow-type-move-into-args branch from 1c3d926 to 9e58c29 Compare March 25, 2022 09:43
@thegreatercurve thegreatercurve force-pushed the flow-type-move-into-args branch from 35ae42c to 4aec50a Compare March 25, 2022 22:54
@thegreatercurve thegreatercurve merged commit e1b67d0 into main Mar 25, 2022
@thegreatercurve thegreatercurve deleted the flow-type-move-into-args branch March 25, 2022 23:13
btezzxxt added a commit that referenced this pull request Apr 1, 2022
acywatson pushed a commit that referenced this pull request Apr 9, 2022
* Move command type out of listener callback to registerCommandListener outer method

* Remove optional chaining

* correct boolean values returned from some command callbacks

* Fix bug with priorty ordering

* clarify type

* Fix failing E2E

* Fix E2E bug

* Wrap mutiple commands in withSubscriptions

* update docs

* Address small issues and add unit test

* remove console logs

* Fix E2E bugs

* Fix E2E bugs

* Remove flow fixmes and add invariant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants