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

Performance improvement on parsing from html #790

Merged
merged 8 commits into from
Mar 7, 2019

Conversation

hypest
Copy link
Contributor

@hypest hypest commented Mar 6, 2019

This PR introduces a couple of speed of optimizations to address the slow start of the editor when the content is large. Relevant issue on wpandroid: wordpress-mobile/gutenberg-mobile#672

What's included:

  1. A new, additional parseHtml... method (parseHtmlForInspection). This one is forked from fromHtml() and has these optimizations:
    a. Use of SpannableString instead of SpannableStringBuilder. We don't want the (slower) ...Builder variant here since we're not planning on modifying the text content of the String while processing it in this method. Some other functions were changed from expecting SpannableStringBuilder to expecting a Spannable since they didn't actually needed the editability SpannableStringBuilder.
    b. Don't use the very expensive addVisualNewlinesToBlockElements() since the parsed content is not going to be used for rendering it in the editor.
    c. Don't use markBlockElementsAsParagraphs() since the spannable will not be used for editing at all so, no need for the PARAGRAPH_SPAN span behavior.
    d. Don't use cleanupZWJ() as it doesn't matter
  2. Added a LIFO tagStack to optimize the handling of end-tags in AztecTagHandler.kt. Up to now, AztecTagHandler.end() was using getLast() which scans the spans to find the most recent "open" tag, but that can be sped up since we know about the nested nature of the html tags. So, a LIFO tracks the opening/closings of the tags and we normally expect the most recent open tag to be exactly at the top of the stack.

Test A

  1. Editing in the demo app should work as normal

Test B

  1. Use this wpandroid PR and verify that the starting of the editor is now faster on long posts.

Review

@[USER_NAME]

Copy link
Contributor

@daniloercoli daniloercoli left a comment

Choose a reason for hiding this comment

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

Demo app works fine.
Also tried all kind of tests attached to the project and they worked as expected.

@hypest
Copy link
Contributor Author

hypest commented Mar 7, 2019

Mario mentioned to me over Slack that he has no further review comments to add so, this is now 👍 to merge when CI passes.

@hypest hypest merged commit c92ff7b into develop Mar 7, 2019
@hypest hypest deleted the feature/performance-improvement branch March 7, 2019 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants