Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Change 'lookUpwardForInlineStyle' from O(n^2) to O(n). #1429

Closed

Conversation

lemmih
Copy link
Contributor

@lemmih lemmih commented Oct 12, 2017

Summary

The function 'lookUpwardForInlineStyle' repeatedly called 'getPreviousBlock' which has the complexity O(n). This tanks performance when creating a document with lots of empty lines. Simply holding down the enter key will quickly cause the frame rate to drop below 1fps.

The fix is straightforward and, in my opinion, preferable to a while loop.

Test Plan

I did some manual testing. The code was able to correctly (and efficiently) find the correct style.

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@flarnie flarnie self-requested a review October 13, 2017 16:03
@flarnie flarnie added this to the v0.10.4 milestone Oct 13, 2017
Copy link
Contributor

@flarnie flarnie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

ilikethisdiffanother

I'll add this to my queue for merging. Thanks!

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@flarnie is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@flarnie has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

midas19910709 added a commit to midas19910709/draft-js that referenced this pull request Mar 30, 2022
Summary:
**Summary**

The function 'lookUpwardForInlineStyle' repeatedly called 'getPreviousBlock' which has the complexity O(n). This tanks performance when creating a document with lots of empty lines. Simply holding down the enter key will quickly cause the frame rate to drop below 1fps.

The fix is straightforward and, in my opinion, preferable to a while loop.

**Test Plan**

I did some manual testing. The code was able to correctly (and efficiently) find the correct style.
Closes facebookarchive/draft-js#1429

Differential Revision: D6060417

fbshipit-source-id: 8a14af25f776ac5263747e2fc4bbb665884ad970
alicayan008 pushed a commit to alicayan008/draft-js that referenced this pull request Jul 4, 2023
Summary:
**Summary**

The function 'lookUpwardForInlineStyle' repeatedly called 'getPreviousBlock' which has the complexity O(n). This tanks performance when creating a document with lots of empty lines. Simply holding down the enter key will quickly cause the frame rate to drop below 1fps.

The fix is straightforward and, in my opinion, preferable to a while loop.

**Test Plan**

I did some manual testing. The code was able to correctly (and efficiently) find the correct style.
Closes facebookarchive/draft-js#1429

Differential Revision: D6060417

fbshipit-source-id: 8a14af25f776ac5263747e2fc4bbb665884ad970
aforismesen added a commit to aforismesen/draft-js that referenced this pull request Jul 12, 2024
Summary:
**Summary**

The function 'lookUpwardForInlineStyle' repeatedly called 'getPreviousBlock' which has the complexity O(n). This tanks performance when creating a document with lots of empty lines. Simply holding down the enter key will quickly cause the frame rate to drop below 1fps.

The fix is straightforward and, in my opinion, preferable to a while loop.

**Test Plan**

I did some manual testing. The code was able to correctly (and efficiently) find the correct style.
Closes facebookarchive/draft-js#1429

Differential Revision: D6060417

fbshipit-source-id: 8a14af25f776ac5263747e2fc4bbb665884ad970
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants