4 ms·
Can I borrow some knowledge? What sort of operations trigger a reflow and repaint?
by QuadmasterXLII 3y ago
Can I borrow some knowledge? What sort of operations trigger a reflow and repaint?
- lioeters 3y ago"Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout." > What forces layout/reflow. The comprehensive list. > All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck. https://gist.github.com/paulirish/5d52fb081b3570c81e3a https://gist.github.com/paulirish/5d52fb081b3570c81e3a
- nostrademons 3y agoShort answer: anything that modifies the DOM, followed by a call which measures geometric properties of the DOM. Also you get an automatic reflow/repaint when control leaves the Javascript event handler that triggers a modification (this is how the browser's UI is updated). You can batch up a bunch of modifications without triggering a reflow and then have it account for all of them on next reflow, though, which is what React tries to achieve with the Virtual DOM and what you get for free after ~2013. Slightly longer answers: [modifies] https://developers.google.com/speed/docs/insights/browser-reflow https://developers.google.com/speed/docs/insights/browser-re... [measures] https://gist.github.com/paulirish/5d52fb081b3570c81e3a https://gist.github.com/paulirish/5d52fb081b3570c81e3a Also there's a bunch of exceptions where you can modify things without triggering a full reflow. Anything that takes elements out of normal flow (position: fixed, position: absolute, float:, overflow: hidden) creates a layout boundary where changes inside only reflow the containing element. Any element with a transform: or opacity: property gets rendered as a 2D texture on the GPU, and then you can do subsequent transform/opacity animations purely on the GPU without touching the CPU. Used to do this to make performant animations on mobile devices.