react-diff-viewer-continued icon indicating copy to clipboard operation
react-diff-viewer-continued copied to clipboard

infinite loading + loading text prop + worker to avoid blocking main …

Open puneet-goel opened this issue 7 months ago • 10 comments

I identified two main issues impacting performance with large diff files:

  1. The computeLineInformation method is time-consuming and runs on the main UI thread, causing the screen to freeze.
  2. The diff viewer renders all content at once, even when much of it isn't visible to the user, leading to unnecessary processing.

These issues result in a laggy and unresponsive user experience for large diffs. To address them, I implemented the following improvements:

  1. Loading Indicator: Introduced a loadingText prop to show a loading element while the diff is being computed.
  2. Infinite Loading Support: Instead of rendering all diff lines at once, the viewer now renders a fixed number initially and loads more on scroll. This is controlled via a new infiniteLoading object with two fields: pageSize and containerHeight.
  3. Caching: Added caching for the results of computeLineInformation and computeHiddenBlocks to avoid redundant computations.
  4. Web Worker Integration: Offloaded the computeLineInformation method to a web worker to prevent blocking the main UI thread.

I’ve also updated the example file and JSONs with large inputs to help test and validate performance improvements.

puneet-goel avatar May 17 '25 17:05 puneet-goel

Issue: https://github.com/Aeolun/react-diff-viewer-continued/issues/66

puneet-goel avatar May 17 '25 17:05 puneet-goel

@puneet-goel Just a thought: loadingText as a prop name seems a bit misleading (when the prop itself accepts a React element) - perhaps loadingContent or loadingElement?

Overall, great work on this, your efforts are much appreciated!

reinrl avatar May 19 '25 16:05 reinrl

@Aeolun Please review and merge for publication. Thank you~!

yangzi0210 avatar May 26 '25 10:05 yangzi0210

@puneet-goel Just a thought: loadingText as a prop name seems a bit misleading (when the prop itself accepts a React element) - perhaps loadingContent or loadingElement?

Overall, great work on this, your efforts are much appreciated!

Hi @reinrl, thank you for the suggestion, I've resolved the same.

puneet-goel avatar May 27 '25 16:05 puneet-goel

@Aeolun Really excited about this one! I think it's a great improvement for performance.

anilpixel avatar Jun 18 '25 06:06 anilpixel

@Aeolun

yangzi0210 avatar Jul 16 '25 07:07 yangzi0210

@puneet-goel

Try sending him an email. I noticed that he has been pushing Git code recently, but I'm not sure why he hasn't been reviewing this merge.

[email protected]

yangzi0210 avatar Jul 23 '25 03:07 yangzi0210

@yangzi0210 Mostly I'm just not paying attention to github notification. I was under the impression it was a month since I'd last checked, but it seems it's been more like half a year 😭

Aeolun avatar Sep 17 '25 05:09 Aeolun

@Aeolun Very understandable, your work should be very busy. Please take some time to handle this PR, which is really useful for our users 🙏🏻

yangzi0210 avatar Sep 17 '25 11:09 yangzi0210

@Aeolun Really excited about this one! I think it's a great improvement for performance.

yangziao2002-coder avatar Oct 29 '25 06:10 yangziao2002-coder