In a tight loop that appends and removes hidden iframes, Chrome did extra work per iframe and slowed down badly for large counts.
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;
Enter a count and click Run.
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
Added: HTMLIFrameElementSimTest.RapidCreateAndRemoveIframesDoesNotRetainDetachedFrames
It creates/removes 500 iframes, forces GC, and checks that frame/document/node instance counters return to baseline.
Chromium commit: 663785ad61874
Headline: Avoid redundant about:blank navigation for new iframes
Bug: 428258024
<!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>