Skip to content

Fix JSON diff viewer performance issue causing UI freeze with large p… - #19

Open
sneha0099 wants to merge 7 commits into
keploy:masterfrom
sneha0099:fix-json-diff-viewer-causing-UI-freeze-with-large-payloads
Open

Fix JSON diff viewer performance issue causing UI freeze with large p…#19
sneha0099 wants to merge 7 commits into
keploy:masterfrom
sneha0099:fix-json-diff-viewer-causing-UI-freeze-with-large-payloads

Conversation

@sneha0099

@sneha0099 sneha0099 commented Sep 3, 2025

Copy link
Copy Markdown

Fixes #18

  • optimized functions.
  • for large payload data.
  • now can load 15k line data.
Screen.Recording.2025-09-03.011242.online-video-cutter.com.mp4

…ayloads

Signed-off-by: Sneha Prajapati <snehaprajapati678@gmail.com>
Copilot AI review requested due to automatic review settings September 3, 2025 07:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes the JSON diff viewer to handle large payloads by implementing virtual rendering with chunked loading to prevent UI freezes. The key improvements focus on performance enhancements that allow the component to display 15k+ lines of data smoothly.

  • Implements chunked rendering with progressive loading using requestIdleCallback
  • Optimizes core diff computation functions by replacing array methods with for-loops and improving data structures
  • Refactors render logic to use iterative approaches instead of functional array methods

Reviewed Changes

Copilot reviewed 4 out of 8 changed files in this pull request and generated 3 comments.

File Description
src/index.tsx Adds chunked rendering state management and progressive loading logic to prevent UI blocking
src/compute-lines.ts Optimizes diff computation performance by replacing forEach/map with for-loops and using Set for lookups
lib/index.js Compiled JavaScript output reflecting the TypeScript changes in index.tsx
lib/compute-lines.js Compiled JavaScript output reflecting the TypeScript optimizations in compute-lines.ts

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/index.tsx Outdated
Comment on lines +530 to +539
if (
visibleNodes.length < computeLineInformation(
oldValue,
newValue,
this.props.noise,
this.props.disableWordDiff,
this.props.compareMethod,
this.props.linesOffset,
).lineInformation.length
) {

Copilot AI Sep 3, 2025

Copy link

Choose a reason for hiding this comment

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

The computeLineInformation function is called on every render to check if more chunks need loading. This expensive computation should be cached or moved to avoid repeated calculations during progressive rendering.

Copilot uses AI. Check for mistakes.
Comment thread src/index.tsx Outdated
Comment on lines +540 to +544
requestIdleCallback?.(() => {
this.setState((prev) => ({
renderedChunks: prev.renderedChunks + 1,
}));
});

Copilot AI Sep 3, 2025

Copy link

Choose a reason for hiding this comment

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

Multiple requestIdleCallback calls could be queued simultaneously during fast renders, leading to unnecessary state updates. Consider debouncing or checking if a callback is already pending before scheduling another one.

Copilot uses AI. Check for mistakes.
Comment thread src/compute-lines.ts Outdated
Comment on lines +475 to +482
if ((oldString.startsWith('{') || oldString.startsWith('[')) &&
(newString.startsWith('{') || newString.startsWith('['))) {
try {
JSON.parse(oldString);
JSON.parse(newString);
isJSON = true;
} catch {
isJSON = false;

Copilot AI Sep 3, 2025

Copy link

Choose a reason for hiding this comment

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

JSON detection logic is too simplistic. Strings that start with '{' or '[' but aren't valid JSON will still attempt JSON parsing, potentially causing performance issues with large invalid JSON-like strings. Consider adding a more robust JSON detection or limiting the size of strings that undergo JSON parsing attempts.

Copilot uses AI. Check for mistakes.
@Sarthak160

Copy link
Copy Markdown
Contributor

@sneha0099 Please check the failing tests and look into the copilot comments

Signed-off-by: Sneha Prajapati <snehaprajapati678@gmail.com>
@sneha0099

Copy link
Copy Markdown
Author

Key Changes:

  • Chunked Rendering & State Management

  • Implements progressive loading to render large diffs in smaller chunks.

  • Prevents UI blocking and freezing when handling massive payloads.

  • Adds state management to track and control incremental rendering.

Optimized Diff Computation

  • Replaces forEach and map with traditional for loops for better performance.

  • Uses Set for lookups instead of arrays to reduce time complexity for large datasets.

  • Minimizes unnecessary computations to improve overall diff calculation speed.

@sneha0099

sneha0099 commented Sep 5, 2025

Copy link
Copy Markdown
Author
  • Used virtual window
  • That renders the data on demand when user scrolls to the bottom
  • It can render 100k lines without any freeze now
  • It inserts data to dom and removes when the user moves or scrolls to bottom
  • So it wont store all the data and wont make it laggy.

Signed-off-by: Sneha Prajapati <snehaprajapati678@gmail.com>
@sneha0099

sneha0099 commented Sep 8, 2025

Copy link
Copy Markdown
Author
  • Issue:

    • If we have large test report data, Then currently this is freezing the UI

    • Because it is loading all data once and that's expensive and time consuming and blocking performance and all data is added in dom directly.

  • Fix:

    • To solve this I've rendered data on demand using react window, when the user scrolls then new data is added in dom and when user scrolls again old data is removed from dom as this is not visible now.

    • This can now load 100k lines without any freeze.
      100k lines of expected and 100k lines of actual data can be compared and can show the diffs without any freeze.

    • used one unifiedGutter function instead of separate gutter functions

    • loaded data based on size:

    • if the size is <700 then it wont render virtually and can see it directly

    • for 700 to 100k line size it renders using virtualization.


  • for <700 lines
Screen.Recording.2025-09-08.172756.mp4

  • for 700 to 100k lines
Screen.Recording.2025-09-09.231846.mp4

Signed-off-by: Sneha Prajapati <snehaprajapati678@gmail.com>
Signed-off-by: Sneha Prajapati <snehaprajapati678@gmail.com>
@manasmanohar

Copy link
Copy Markdown
Member

@sneha0099 please look into the failing pipeline

Signed-off-by: Sneha Prajapati <snehaprajapati678@gmail.com>
Signed-off-by: Sneha Prajapati <snehaprajapati678@gmail.com>

@manasmanohar manasmanohar 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.

@sneha0099 could you please fix the failing pipeline as well with this pr. Having the test pipeline will help catch bugs earlier going ahead.

@sneha0099

Copy link
Copy Markdown
Author

@manasmanohar

it is giving this
Running self-installer...
Error: Something went wrong, self-installer exits with code 1
Installation Completed!

what can be the issue? Have you any idea because it's only giving something went wrong.
the solution's is working fine i ran this locally using this library

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.

Fix JSON diff viewer performance issue causing UI freeze with large payloads

4 participants