iframe create/remove slowdown

#428258024 Filed 2025-06-28 New (fix prepared)

Summary

What was happening

In a tight loop that appends and removes hidden iframes, Chrome did extra work per iframe and slowed down badly for large counts.

Fix

For newly created subframes, Blink already has the initial empty document from FrameLoader::Init(). The code then started a second synchronous about:blank navigation. The fix skips that redundant navigation.

if (url_to_request == BlankUrl()) return true;

Reproducer

Enter a count and click Run.

Results

Before fix (500 cycles, blink_unittests):
  total:      ~3165ms
  appendChild ~2516ms

After fix (500 cycles, blink_unittests):
  total:      ~771ms
  appendChild ~546ms

Improvement:
  ~4.1x faster overall
  ~4.6x faster append path

Regression test

Added: HTMLIFrameElementSimTest.RapidCreateAndRemoveIframesDoesNotRetainDetachedFrames

It creates/removes 500 iframes, forces GC, and checks that frame/document/node instance counters return to baseline.

Patch

Chromium commit: 663785ad61874
Headline: Avoid redundant about:blank navigation for new iframes
Bug: 428258024

Original testcase

<!DOCTYPE html>
<html>
<body>
  <input id="n">
  <button onclick="go()">Go</button>
  <script>
    function go() {
      let n = +document.getElementById('n').value;
      for (let i = 0; i < n; i++) {
        let f = document.createElement('iframe');
        f.style.border = 'none';
        f.style.width = '0';
        f.style.height = '0';
        f.style.display = 'none';
        document.body.appendChild(f);
        document.body.removeChild(f);
      }
    }
  </script>
</body>
</html>