-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
transform.delete and transform.insertFragment performance optimize #5137
Conversation
🦋 Changeset detectedLatest commit: 317fa6b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Ultimately we need operations like |
I think current create new Operations will affect OT transform logic,which will case more problems to consider |
@bryanph any further thoughts after #5137 (comment) ? |
@dylans Not really, overall this seems like a valid optimization to me edit: I do have one question actually, do we know why this is so slow with immer? It's just operating on a flat array, seems like that should be comparable in performance to destructuring and applying changes to that? |
They used to not recommend immer on arrays with thousands of items, but that doesn't seem to be part of their performance tips any more: https://immerjs.github.io/immer/performance#performance-tips |
…anstormtaylor#5137) * feat: transform.delete and transform.insertFragment performance optimize * feat: add changeset * feat: optimize code Co-authored-by: mainhanu <chijun89@gmail.com>
Description
delete and insert large fragment can be very time consuming,the time complexity is
O(n2)
Example
environment
MacBook Pro (13-inch, 2019) 2.4 GHz 4 Intel Core i5
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
result:
2000
pargagraphsbut with
200
pargagraphsContext
The reason is related to the number of path refs in the apply process.
for
transform.delete
, The following code causes each apply to process the path transform of the first i-1 paragraphs.we can remove nodes from last to first to avoid use path ref.
for
transform.insertFragment
, theO(n2)
has something todo with the dirtyPath logic, each insertNode will add new dirtyPath to DIRTY_PATHS and subsquentapply
will transform all previous dirtyPath。I hadn't figure out how to opitimize it。according to the logic, move large fragment may also has the same problem。I just add a tiny optimization to
Path.transform
, array destruction is faster thanimmer's produce
, and it also make remove 2000 paragraphs 3x faster。after optimize
delete 2000 paragraphs
delete 200 paragraphs
Checks
yarn test
.yarn lint
. (Fix errors withyarn fix
.)yarn start
.)yarn changeset add
.)