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 regression from dom to hooks

See original GitHub issue

šŸ› Bug description

I noticed that performance of updating the search query became quite a bit worse when I changed from -dom to -web-hooks.

Some functions that seem responsible for pretty much all of the wait time:

  • escapeHits
  • recursiveEscape
  • getWidgetRenderState

Screenshot 2022-11-17 at 22 07 00

Screenshot 2022-11-17 at 22 18 03

šŸ” Bug reproduction

Steps to reproduce the behavior:

  1. Set up a basic React-Instantsearch with Hits and SearchBox with react-instantsearch-dom
  2. Start typing, note the quick rendering
  3. Switch to react-instantsearch-dom
  4. Start typing, note the slower rendering

Sorry for the lack of demo repo, my project is currently closed source. I’ll try to dive in deeper, I’ll update this issue

Some findings / thoughts:

  • The issue scales with the amount of HitsPerPage
  • Even if my custom Hit component returns null, the issue is bad, so it’s not really the rendering part, I think.
  • It may have something to do with my relatively large documents, which contains many keys (about 100 KV combos)

Live reproduction:

https://codesandbox.io/s/github/algolia/react-instantsearch/tree/master/examples/hooks

Environment

  • React InstantSearch Hooks version: 6.38.0
  • React version: 18.2.0
  • Browser: Firefox 108
  • OS: MacOS

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
joepiocommented, Dec 22, 2022

@Haroenv

No multiple components, but I do have a useHits somewhere else to render the count.

Let me try this:

  let {
    results: { nbHits },
    hits,
  } = useHits({
    escapeHTML: false,
  });
1reaction
Haroenvcommented, Dec 13, 2022

escapeHTML can be avoided in React, because you don’t render dangerouslySetInnerHTML, therefore it can be faster if you do this:

https://codesandbox.io/s/silly-fermi-qj4dbn?file=/App.tsx:4270-4410

I’ll think about how this can be improved and leads to less wasted cycles by default too

Read more comments on GitHub >

github_iconTop Results From Across the Web

Detecting when React Components are Visually Rendered as ...
In this tip, I'll demonstrate a simple React Hook for determining when your React Component has presented itself visually to the user viaĀ ......
Read more >
React Hooks to optimize performance | by Gerardo FernƔndez
In this article and taking advantage of the consolidation of the React Hooks I want to present a couple of solutions that can...
Read more >
Testing the React Router useNavigate Hook ... - LogRocket Blog
You can use the useNavigate Hook to navigate to other pages, as seen in the code block below: import { useNavigate } from...
Read more >
React Virtual Dom and Memo on Performance - Medium
I will explain the Virtual Dom concepts, Memo, useMemo hook in detail including,. What they are? How they are gaining performance?
Read more >
React hooks: call component as function vs render as element
Here are some implications of calling component as function vs rendering it as element. Potential violation of rules of hooks.
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