1 of 50

Big Data, Zero JSCross-Browser Virtual Scrolling�CONTAIN & CONTENT-VISIBILITY

2 of 50

when you want to center a div in chrome

3 of 50

contain: paint

contain: layout

content-visibility: auto

contain: content

contain: strict

Layout

Hit Test

Recalc Style

Event

<

Paint

Composite

4 of 50

runtime

Drastic performance impact with latest CSS features

bootstrap

before

after

5 of 50

Michael Hladky / @Michael_Hladky

CEO / GDE for Angular, MVP, Nx Champion

push-based.io

Improve Web Performance

Scale productivity with Nx

Architect with JS & Angular

6 of 50

browser render waterfall

Layout

Recalc Style

Event

<

Paint

Composite

<

{ }

<

🔁

7 of 50

Scripting

{ }

Recalculate Styles

calculate

Recalc Style

Event

<

introduce changes to DOM or styles

apply CSS to the related DOM

8 of 50

on UI interaction map to DOM nodes

Layout

Hit Test

Layout

Hit Test

calculate the nodes dimensions

9 of 50

Paint

Composite

Paint

Composite

compute overlaps of the layers

fills pixels on layers

10 of 50

Browser

Layout

Hit Test

Recalc Style

Event

<

Paint

Composite

<

{ }

<

🔁

render

pipeline

<

11 of 50

render performance concepts

border-box

visible boundary

screen viewport

limit�paint area

reduce nodes �to layout

skip recalc styles for

offscreen nodes

12 of 50

CSS:

Triggers

13 of 50

Full Page: Trigger

14 of 50

Test: Setup

15 of 50

contain: layout | paint | size | style�content | strict

16 of 50

17 of 50

contain: layout

contain: paint

contain: size

border-box is the �visible boundary

layout relative�to border-box

border-box requires �dimensions

18 of 50

contain: layout

19 of 50

20 of 50

performance impact

skip child nodes �from layouting

contained nodes

offscreen nodes

shield from �outer layout

contains inner layouting

contain: layout

21 of 50

design impact

layout relative�to border-box

absolute nodes

contained nodes

relative positionform container

new stacking-context

for children

contain: layout

z-2

z-1

22 of 50

The Drawback: Of Layout

23 of 50

Test: Layout impact

24 of 50

the target nodes DOM contains only layout work, the example contains a trigger which effects only layout properties, the measure is performed in 3 steps form none to layout and one with layout and all nodes offscreen

contain: layout - lab measurement

onscreen

offscreen

11ms Update Layer Tree

0,5ms Update Layer Tree

0,5ms Update Layer Tree

unoptimized

25 of 50

contain: paint

26 of 50

performance impact

contained nodes

obscured nodes

offscreen nodes

shield from �outer paint

reduces paint area by cutting edges

skip invisible nodes from paint

contain: paint

paint area reduced �to border-box

offscreen container

skip out of viewport�nodes from paint

27 of 50

design impact

visible area

cuts paint area �at border-box

contain: paint

border-box is the �visible boundary

28 of 50

The Drawback: Of Paint

29 of 50

Test: Paint impact

30 of 50

the target nodes DOM contains only paint work, the example contains a trigger which effects only paint properties, the measure is performed in 3 steps form none to paint and one with paint and all nodes offscreen

6.00ms Paint

1.00ms Paint

0.15ms Paint

unoptimized

onscreen

offscreen

contain: paint - lab measurement

31 of 50

contain: size

32 of 50

performance impact

contained nodes

ignores nodes

for size calculation

contain: size

border-box requires �dimensions

33 of 50

design impact

static dimensions

container dimensions

collapse

border-box requires �dimensions

34 of 50

contain: shorthands

35 of 50

contain: content

contain: strict

contain:layout paint size

contain:�layout paint

36 of 50

contain: layout paint size

Value

Usage

Impact

Layout Root

Overflow

Dimensions

none

n/a

n/a

document

visible

optional

layout

easy

++

node

visible

optional

paint

moderate

+

node

hidden

optional

size

hard

~

document

visible

required

Shorthands

content

moderate

+++

node

hidden

optional

strict

hard

+++~

node

hidden

required

37 of 50

Viewport Concepts

<body>

<card>

<card>

<card>

<list>

<card>

<card>

<card>

<card>

above the fold(onscreen nodes)

visual boundary

<card>

<card>

below the fold�(offscreen nodes)

offscreen

obscured

38 of 50

render performance concepts

viewport

viewport observation

size observation

track visibility �of nodes

skip recalc styles for

offscreen nodes

track dimensionsof nodes

39 of 50

content-visibility: auto|hidden�contain-intrinsic-size: px|auto

40 of 50

41 of 50

performance impact

contained nodes

nodes layout benefits

from contain

content-visibility: auto

border-box requires �dimensions offscreen

offscreen nodes

ignores nodes

outside the viewport

contained nodes

nodes paint benefits

from contain

42 of 50

design impact

static dimensions

border-box requires �dimensions offscreen

content-visibility: auto

ignores nodes

outside the viewport

43 of 50

6.00ms Paint

1.00ms Paint

0.1ms Paint

unoptimized

onscreen

offscreen

11ms Update Layer Tree

0,5ms Update Layer Tree

61 μs Update Layer Tree

content-visibility: auto - lab measurement

44 of 50

content-visibility: auto

contain-intrinsic-size: px

Value

Usage

Impact Onscreen

Impact Offscreen

Layout Root

Overflow

Dimensions

none

n/a

n/a

n/a

document

visible

optional

auto

moderate

++

+++

node

hidden

required

Value

Usage

Dimensions Onscreen

Dimensions�Offscreen

Impact

none

n/a

n/a

n/a

n/a

px

easy

n/a

given value

stable scrollbar

45 of 50

Demo: Measurement

46 of 50

Unoptimized - bootstrap

Add DOM nodes

offscreen paint / layout of images

layout

hit test, paint , composite

Recalculate styles

47 of 50

Optimized - bootstrap - inc. offscreen nodes

Recalculate styles, hit test, layout, paint ,composite

NO offscreen paint / layout of images

Add DOM nodes

48 of 50

Unoptimized - runtime - inc. offscreen nodes

animation

bootstrap

49 of 50

Optimized - runtime - inc. offscreen nodes

animation

bootstrap

50 of 50

Thanks for Your Time!�Need Help? Just Ping Me!

Michael Hladky / @Michael_Hladky

CEO / GDE for Angular, MVP, Nx Champion

push-based.io

CI | Performance | Architecture