Skip to content

Commit 0579aef

Browse files
committed
Switch demo1 graphics to graphs, and memory pic without extra highlight
1 parent 6d30b66 commit 0579aef

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,21 @@ A custom element that pulls in its styles with CSS module, however, only process
8181

8282
[Demo 1](https://dandclark.github.io/json-css-module-notes/demo1/index.html) illustrates this difference with a custom element written 3 different ways: with a `<style>` element in each shadow root, with a `<link>` element in each shadow root, and with a single CSS module applied to each shadow root's `adoptedStyleSheets`. To make the performance differences easily distinguishable, each page includes 15,000 instances of the respective custom element version.
8383

84-
I generally observe the CSS module element version loading about 1 second faster than the `<style>` element version, though the difference will vary per machine.
84+
The following graph is characteristic of the results:
8585

86-
![`<style>` in shadow root load time](demo1/styleInShadowRootHighlight.PNG)
86+
![Load time of different custom element types](demo1/loadTimeGraph.PNG)
8787

88-
![CSS module load time](demo1/cssModuleHighlight.PNG)
88+
Of course the absolute times will change per machine, but I observe a similar ratio of load times across different environments.
8989

90-
The `<link>` element version loads much more slowly:
90+
Digging into the performance traces, we found that the gains came from the areas we expected:
9191

92-
![`<link>` in shadow root load time](demo1/linkInShadowRootHighlight.PNG)
92+
![CSS module perf win breakdown](demo1/loadTimeTable.PNG)
9393

94-
It's not clear why `<link>` is so much slower; caching should prevent it from making a new network request for each element instance. There might be a Chromium bug here, but in any case we expect that the performance best case should be similar to the `<style>` version.
94+
These results make sense; for the `<link>` and `<style>` approaches, each custom element instance must have its own instance of one of these elements. It takes time to allocate this element, and process its various rules for insertion into the DOM tree. For example, setting up all of the StyleSheet fetches for the `<link>` element approach takes a nontrivial amount of time even though they all end up hitting the cache. With CSS modules on the other hand, there is just a single CSSStyleSheet instance for the entire page.
9595

96-
There are also memory savings from omitting the extra elements. After reaching baseline (putting tabs in background and waiting for final GC at ~60 seconds) I see these numbers:
96+
There are also memory savings from omitting the extra elements. After reaching baseline (putting tabs in background and waiting for final GC at ~60 seconds) I see these numbers like this:
9797

98-
![steady-state memory usage](demo1/steadyStateHighlight.PNG)
98+
![steady-state memory usage](demo1/mem2All.PNG)
9999

100100
### Demo 2: [CSS/JSON modules have a lower memory footprint than inlining the CSS/JSON as a JavaScript string](https://dandclark.github.io/json-css-module-notes/demo2/index.html)
101101
[https://dandclark.github.io/json-css-module-notes/demo2/index.html](https://dandclark.github.io/json-css-module-notes/demo2/index.html)

demo1/loadTimeGraph.png

51.4 KB
Loading

demo1/loadTimeTable.PNG

28.5 KB
Loading

demo1/mem2All.png

9.33 KB
Loading

0 commit comments

Comments
 (0)