question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

domToText: Performance issue in large projects

See original GitHub issue

I’m investigating performance issues when working with large blocks programs (in MakeCode Arcade), and Blockly’s domToText method came up as a hot path due to a regexp replace it executes. This regexp was added in https://github.com/google/blockly/pull/2663 (Textarea Field, Multiline Block (from acbart)). Here’s the line in question: https://github.com/google/blockly/blob/ba68081d8f0f8e81d76baf370716d5955bae82a1/core/xml.js#L319

This regexp runs repeatedly on the document, causing domToText to take a significant amount of time when the xml is very large. Without this regexp, saving takes practically no time at all.

If you could help me understand the purpose of this search/replace, perhaps I could come up with another approach. And if you have a suggestion for how to improve or remove it, I would be happy to try it and report back.

image

OS: Windows 10 Browser: Chrome 83

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
eanders-mscommented, Jul 9, 2020

@BeksOmega thank you that info is super helpful! I made a fix in MakeCode’s fork: https://github.com/microsoft/pxt-blockly/pull/315, and will open one here too.

2reactions
BeksOmegacommented, Jul 9, 2020

Hi! I’m not actually on the Blockly team, but I do know some stuff about this area, and I think I have some ideas =)

So it looks like this was added by the same change that added the multiline input field. It looks like it’s going through and replacing all \n (linebreak) characters with the escaped versions so that the field correctly round-trips through XML.

Example escaped xml:

<xml xmlns="https://developers.google.com/blockly/xml">
  <block type="test_fields_multilinetext" id="jGDBz^O9+Zz6-r@84/|u" x="13" y="13">
    <field name="CODE">default1&#10;default2</field> <!-- See &#10; escaping -->
  </block>
</xml>

So it is necessary for the multiline text field, but I don’t think it’s necessary to run the search-and-replace over /all/ of the XML.

If you want to take a crack at fixing this I would move the search-and-replace into a toXml function that lives on the multiline text field. That should (hopefully) save time in serialization because the search-and-replace will only run when it absolutely has to.

Thank you so much for looking into this that’s really cool!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Megaprojects: The good, the bad, and the better | McKinsey
Building big infrastructure projects is always risky, but there are ways to improve the odds of a smooth landing.
Read more >
a Canadian study: Construction Management and Economics
Comparison of cost and schedule performance of large public projects under P3 and traditional delivery models: a Canadian study.
Read more >
National Science Foundation: Cost and Schedule ...
These large facilities projects typically have construction costs of at least $70 million and may take many years to design and construct.
Read more >
General Resources - Major Projects
FHWA Major Project Guidance Memorandum Section 1904 of the Safe, ... the performance of active major projects and the actions FHWA has taken ......
Read more >
Five Rules for Managing Large, Complex Projects
Recent research on megaprojects — defined as projects costing more ... rules can help improve the performance of big, high-risk projects.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found