Skip to content

Theme UI Performance - #370

Merged
tlgimenes merged 4 commits into
masterfrom
feature/theme-ui-performance
Nov 12, 2020
Merged

tlgimenes merged 4 commits into
masterfrom
feature/theme-ui-performance

Conversation

@tlgimenes

@tlgimenes tlgimenes commented Nov 10, 2020 •

Copy link
Copy Markdown
Contributor

What's the purpose of this pull request?

This PR brings many performance optimizations for our theme-ui plugin.

How it works?

This first optimization explored one of Emotion's most wanted "features". Emotion v10 works out of the box on many frameworks, a.k.a Next.JS, Gatsby and CRA. To make this work, they render a <style/> tag right before an html tag (<div/>) and go through a process of hydration. In this process, they append style nodes to the DOM head. This process is time consuming and may take a long time. However, emotion's own docs show an advanced server side rendering process where we don't need this hydration phase to occur.

Below, you can see the before/after flamechart showing the time it takes to run this function
image
image

The second optimization was due to @emotion/is-prop-valid. This package has a HUGE (4Kb) RegExp. This RegExp can be greatly reduced with a O(1) Hash table. To be able to overwrite this package, I've used the a Webpack alias.
The before/after flamechart can not be shown since this function execution disappeared after the optimization on the flamechart

The third optimization was due to how the merged theme-ui theme object was stringified into the final .js file. To better understand this optimization take a look at this video

After these 3 optimizations combined, we went from ~60ms to ~14ms and the difference can be seen in the comparison below for the E4e1 function
image
image

How to test it?

storecomponents
marinbrasil

References

Spread the knowledge: is there any content you used to create this PR that is worth sharing?

Extra tip: adding references to related issues or mentioning people important to this PR may be good for the documentation and reviewing process

@tlgimenes
tlgimenes requested a review from a team November 10, 2020 20:07
@tlgimenes
tlgimenes requested a review from a team as a code owner November 10, 2020 20:07
@tlgimenes
tlgimenes force-pushed the feature/theme-ui-performance branch from e621149 to 3519c2a Compare November 10, 2020 20:27
@klzns
klzns requested a review from a team November 10, 2020 20:27
@tlgimenes
tlgimenes force-pushed the feature/theme-ui-performance branch 2 times, most recently from 3412ff6 to 59f3862 Compare November 10, 2020 20:48

@emersonlaurentino emersonlaurentino left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Job!

@tlgimenes
tlgimenes force-pushed the feature/theme-ui-performance branch from 178dc21 to 78d6f09 Compare November 12, 2020 13:17
@tlgimenes
tlgimenes merged commit 33f4279 into master Nov 12, 2020
@tlgimenes
tlgimenes deleted the feature/theme-ui-performance branch November 12, 2020 13:41
renatamottam pushed a commit that referenced this pull request Feb 10, 2023
* chore: Updates deps and attempts to replace

* chore: Removes unused payment methods css

* chore: Updates deps

* chore: Updates data-attr name

* chore: Updates deps

* chore: updates packs

* chore: Fixes style

* chore: Updates fs/c package version

* Triggers CI with an empty commit

* Triggers CI with an empty commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants