Giter Site home page Giter Site logo

a-billion-divs-with-content-visibility-auto's Introduction

https://josephrocca.github.io/a-billion-divs-with-content-visibility-auto/

Part of an exploration based on what I thought might have been a Chromium bug related to the new content-visibility:auto.

A Chromium contributor (see Chromium bug link) came up with the idea that you could nest content-visibility:auto divs in a hierarchy such that there's basically no layout/render time for the vast majority of elements (it's not enough to simply add content-visibility:auto to each div, as explained in the Chromium bug link). That means that the number of elements on the page is really only limited by the amount of memory your device has.

I was hoping to get to a billion elements just for fun, but very quickly reached an apparent semi-arbitrary V8 DOM-node limit of roughly 2^24 (guessing it's the same reasoning as here: https://stackoverflow.com/a/54466812/11950764). With content-visibility:auto I can get to about 7 million elements (roughly half of 2^24 - I think because of the text nodes within divs) before a browser crash. Without content-visibility:auto the browser crashes at about 700,000 elements. The latter takes about 10,000ms to layout/render whereas with content-visibility:auto layout/render never takes more than about 150ms, regardless of the number of elements.

But beyond about 50,000 elements the content-visibility:auto approach becomes dominated by the time required to actually create the elements rather than render/layout (which only take about 15% of load time). If the whole document were downloaded (or even just the data to render it) it would be a several-hundred MB download, so the download time would probably dominate for most users (not that any real-world application would load so many elements).

I tried to generate nodes directly (with document.createElement) rather than creating a big string for the browser to parse, but that ended up being really slow. Initially counter-intuitive because I'd have thought that parsing the generated text to make the nodes would be slow relative to creating the nodes directly, but I guess the parser has been very well optimised and is running in native code rather than slower JS code.

One strange thing I noticed is that if you render the page with 5 million elements, and then download it (with right-click, save as), then when you try to load up that pre-rendered file in the browser, it takes a very long time (more than a minute) and then it crashes. Looking at the performance recording it says that it was all spent on rendering. I'd have thought it'd be able to render about as fast as the dynamically-generated case since it's just loading from disk. It's about 200Mb, so it should load into memory in much less than a second, and at that point it seems like it has the same work to do as the dynamically-generated case (i.e. parsing a huge string).

a-billion-divs-with-content-visibility-auto's People

Contributors

josephrocca avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.