question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance issue using Preact and 1.0.0-rc.3

See original GitHub issue

Bug report

Describe the bug

I met this problem when using next.js with preact and 1.0.0-rc.(1|2|3). Everything works in dev mode but when the app is built and run in production mode, the page takes a very long time to load.

To reproduce

I’ve build an demo for this problem.

  1. npm i
  2. npm run build
  3. npm start
  4. Open http://localhost:3000

Minimal reproduction

https://github.com/rjyo/demo-preact-chakraui

Expected behavior

N/A

Screenshots

A simple page with 6 text Input took several seconds before page loaded.

image

System information

  • OS: macOS Catalina 10.15.6
  • Browser (if applies): Chrome
  • Version of @chakra-ui/core: 1.0.0-rc.3
  • Version of Node.js: v12.18.0

Additional context

I know Preact many not be officially supported. Hope you guys have some time to look into this.

How I found this

Comparing 2 simple “Terms of Usage” pages (mostly displaying text), one build with Chakra-UI 0.8 + Preact, another with Chakra-UI rc.3 + React, the score of Google PageSpeed Insights went down quite a lot. More specifically, the Total Blocking Time almost doubled. I thought it could be React’s performance problem but found Chakra-UI rc.3 + Preact doesn’t even work anymore.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
ljosberinncommented, Sep 12, 2020

https://github.com/emotion-js/emotion/pull/896 that will probably explain it 😅 preact is not supported by emotion, should’ve searched earlier, oh well. At least we found that other issue because of this rabbit hole.

3reactions
ljosberinncommented, Sep 12, 2020

I can confirm it is indeed very slow. Now the interesting part:

  • importing this into _app.tsx for debugging reasons, which effectively just enables preact devtools in prod fixes it.
if (typeof window !== 'undefined') {
  require('preact/debug')
}

Obviously that can’t be the solution, so I also added @zeit/next-source-maps to the next.config.js. Using chromes Performance tab, I could track down the issue: useStyleConfig using lodash.merge.

image

In your case, its twice as bad because youre passing a theme thats the default theme, which we then merge… with the default theme. I think we can omit that merge process just by comparing those.

Merging the theme with itself isn’t horribly unperformant actually, but as you can see here, each useStyleConfig('Form', ...) takes ages. Really weird behaviour considering this only happens with Preact.

image

Digging some more and will update.

Edit: sadly cant compare outerTheme === theme in theme provider. but you shouldnt pass the default theme anyways, so that would be user error anyways. and 4ms isnt too bad.

Edit 2: found it 🎉 I think

Edit 3: yep.

https://github.com/chakra-ui/chakra-ui/blob/develop/packages/system/src/use-style-config.ts#L30 rest contains children. merge deepmerges. using omit(rest, 'children') reduces repeated executions to <1 ns again. Will file a PR!

Still no clue how this only happens in Preact though but oh well, this will be a perf improvement for everyone.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Switching to Preact (from React)
Everything you need to know to switch from React to Preact.
Read more >
preact - Bountysource
I have some existing react libraries and a react app which I am trying out with preact. It is working fine but I...
Read more >
@mdx-js/mdx - npm
MDX compiler. Latest version: 2.2.1, last published: 5 days ago. Start using @mdx-js/mdx in your project by running `npm i @mdx-js/mdx`.
Read more >
Preact - Releases
One seemingly minor change to our jsx constructor function lead to pretty weird and nasty bug depending on whether the code was run...
Read more >
React v17.0 Release Candidate: No New Features
Fixing Potential Issues. As with any breaking change, it is likely some code would need to be adjusted. At Facebook, we had to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found