Perf: Move multiline xml text encoding out of domToText#4046
Merged
samelhusseini merged 2 commits intoJul 14, 2020
Conversation
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
samelhusseini
approved these changes
Jul 14, 2020
Contributor
samelhusseini
left a comment
There was a problem hiding this comment.
LGTM pending CLA. Thank you!
Contributor
Author
|
@googlebot I signed it!
|
|
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
Contributor
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The basics
The details
A complex regular expression in
Blockly.Xml.domToTextwas running on every save, causing performance problems on large projects. The regexp progressively replaces all\nwith in content fields, and was added along withFieldMultilineInput, in #2663.Proposed Changes
Override
toXmlandfromXmlonFieldMultilineInputand do the conversion there. This simplifies the regexp, and it only runs when there is multiline content in the program, improving performance - especially on large programs.Performance Comparison
Testing with this MakeCode Arcade game: https://arcade.makecode.com/74548-67333-76127-33508
Time spent in
Blockly.Xml.domToText:Resolves
Resolves #4030
Test Coverage
I tested this change in playground.html. Steps I followed:
Also: In the dev console, set breakpoints in the
toXmlandfromXmlmethods ofFieldMultilineInputto verify they're getting called at the right times.Tested on:
Additional information
Of note: Another document-wide regexp has appeared in
domToText, and will likely become a performance issue. You may want to fix it: https://github.com/google/blockly/blob/ba68081d8f0f8e81d76baf370716d5955bae82a1/core/xml.js#L327I can see how
domToTextwould be a tempting place to fixup formatting issues. It might be worth adding a comment in that method stating: "For performance reasons, don't run regular expressions on the whole document."