Skip to content

DOMParser.parseFromString very slow #37223

@MegaCorn

Description

@MegaCorn

When using the Vue framework, the element.innerHTML interface took a long time.
Seems it was a performance issue with the htmlparser.
The following code only takes 50ms in Chrome on the Windows platform, while it takes 5000ms in Servo.
I was trying to analyze this problem. Any idea to track it?

<script>
    function generateHTML(count) {
      let html = '';
      for (let i = 0; i < count; i++) {
        html += `<div>
                   <h2>Item ${i}</h2>
                   <p>This is paragraph number ${i}</p>
                   <ul>
                     <li>A</li><li>B</li><li>C</li>
                   </ul>
                 </div>`;
      }
      return html;
    }

    document.getElementById("run").addEventListener("click", function () {
      const result = document.getElementById("result");
      const html = generateHTML(5000);
      const parser = new DOMParser();

      const start = performance.now();
      const doc = parser.parseFromString(html, "text/html");
      const end = performance.now();

      result.textContent = `total: ${(end - start).toFixed(2)} ms`;
    });
</script>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions