Notes on Twind runtime performance (observe/shim, just-in-time stylesheet creation) #161
Replies: 3 comments 19 replies
-
@sastan you can see in the performance flamegraph (immediately above) the |
Beta Was this translation helpful? Give feedback.
-
@sastan I added the following paragraph in the introduction post, to avoid misleading readers:
|
Beta Was this translation helpful? Give feedback.
-
I also added the following clarification in the thread: **EDIT: this is a suboptimal method for loading Twind, due to the async / deferred nature of ECMAScript modules. Traditional script loading yields much better perceived and measured performance due to scheduling layout recalc in relation to the DOMContentLoaded event. Please make sure to read the entire thread below to see much improved performance figures :) ** |
Beta Was this translation helpful? Give feedback.
-
Discussion topic started in this "issue":
#157 (comment)
(moved here to avoid polluting the main conversation thread)
Fun test: use Twind/shim to render https://tailwindcss.com (a really impressive landing page packed with cool interactives!)
SPOILER ALERT: Twind shim/observe is slower than precompiled stylesheets, and on first impression it even seems much slower. However when configured appropriately, it is actually impressively fast! Details below.
I "downloaded" a local copy of the website's landing page ("save as" from Chrome), and I ran Lighthouse's "performance" test from a localhost HTTP server:
Desktop:
Mobile:
Then, I removed the Tailwind CSS stylesheet, and I added:
<script type="module" src="https://cdn.skypack.dev/twind/shim"></script>
(Skypack CDN, but I ran a local test too, see further below)
**EDIT: this is a suboptimal method for loading Twind, due to the async / deferred nature of ECMAScript modules. Traditional script loading yields much better perceived and measured performance due to scheduling layout recalc in relation to the DOMContentLoaded event. Please make sure to read the entire thread below to see much improved performance figures :) **
Desktop:
Mobile:
Finally, I replaced the Skypack CDN Twind/shim script link with locally-hosted copies:
Desktop
Mobile
Here's the performance flamegraph:
Without Twind:
With Twind:
(the activity graph on the left hand side is Twind's
observe
aka "shim" immediately afterDOMContentLoaded
, working its way through the DOM to build the stylesheet just-in-time)@sastan :
Sure. My current test is with:
Much better :)
Desktop
Mobile
Interesting flamegraph now:
Beta Was this translation helpful? Give feedback.
All reactions