Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poor performance on re-render #302

Closed
samuela opened this issue Aug 18, 2020 · 7 comments
Closed

Poor performance on re-render #302

samuela opened this issue Aug 18, 2020 · 7 comments

Comments

@samuela
Copy link

samuela commented Aug 18, 2020

Describe the bug
Any time React does a re-render on the SyntaxHighlighter component, the component does a full re-parse, re-highlight of the entire document even when the document hasn't changed. The most egregious offender is getCodeTree and next up is processLines.

I think the fix here is to simply wrap these in useMemo.

To Reproduce
Steps to reproduce the behavior:

  1. Render a large file.
  2. Note that re-renders are still very slow.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
Screen Shot 2020-08-18 at 1 11 27 PM

Video: https://youtu.be/N01PEn3BZIk

Desktop (please complete the following information):

  • OS: macOS 10.15.4
  • Browser Chrome, FireFox

Additional context
Add any other context about the problem here.

@ygorduraes
Copy link

I'm having this same problem with large files. I still haven't found a workaround for this issue.

@travisdahl
Copy link

Having the same issue. Unusable with large files.

@francostramana
Copy link

Any solution? It's really a big problem.

@karlhorky
Copy link
Contributor

I think this may be fixed by #394 by @xiangst0816

This has been merged, but not yet released (maybe it will become 15.4.6)

cc @conorhastings

@simmerer
Copy link
Collaborator

15.5.0 (released this morning) contains @xiangst0816 's fix from #394

@karlhorky
Copy link
Contributor

Thanks @simmerer !

@iampava
Copy link

iampava commented Jul 3, 2023

I don't think this is fixed. The correct solution, as mentioned here #303 should be useMemo

A hack I did in my app, that helped is to actually memoize the component myself

const memoizedHighlighter = useMemo(
      () => (
        <SyntaxHighlighter>
          {code}
        </SyntaxHighlighter>
      ),
      [code]
    );

 return (
      <div>
        {memoizedHighlighter}
      </div>
    );

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

No branches or pull requests

7 participants