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

Session player UI performance improvements #8836

Closed
linear bot opened this issue Jun 24, 2024 · 2 comments
Closed

Session player UI performance improvements #8836

linear bot opened this issue Jun 24, 2024 · 2 comments

Comments

@linear
Copy link

linear bot commented Jun 24, 2024

Issues with repainting and causing lagging when the user interacts with the session player

Issues:

Copy link
Author

linear bot commented Jun 24, 2024

Copy link

greptile-apps bot commented Jun 24, 2024

To address the session player UI performance issues, consider the following steps:

  1. Throttling and Debouncing: Ensure that event handlers, especially those related to user interactions like resizing and scrolling, are throttled or debounced to prevent excessive re-renders.

    import { throttle } from 'lodash';
    
    const onViewportChange = useCallback(
      throttle((_e) => {
        dispatch({
          type: PlayerActionType.updateViewport,
          viewport: _e as viewportResizeDimension,
        });
      }, FRAME_MS * 60),
      [],
    );
  2. Memoization: Use useMemo and useCallback hooks to memoize expensive calculations and functions to avoid unnecessary re-renders.

    const playerFiller = useMemo(() => {
      const playerHeight = playerWrapperRef.current?.getBoundingClientRect().height;
      const height = ((playerHeight ?? 0) * 3) / 5;
      return <LoadingBox width={controllerWidth} height={height} />;
    }, [controllerWidth]);
  3. Conditional Rendering: Avoid rendering components that are not visible or necessary. For example, conditionally render the PlayerCommentCanvas only when the player is ready.

    {isPlayerReady && (
      <PlayerCommentCanvas
        setModalPosition={setCommentModalPosition}
        modalPosition={commentModalPosition}
        setCommentPosition={setCommentPosition}
      />
    )}
  4. Batch State Updates: Use useReducer to batch state updates and reduce the number of re-renders.

    const [state, dispatch] = useReducer(PlayerReducer, {
      ...PlayerInitialState,
      chunkEventsRef,
      isLoggedIn,
      isHighlightAdmin,
      markSessionAsViewed,
      fetchEventChunkURL,
    });
  5. Optimize CSS: Ensure that CSS animations and transitions are optimized and do not cause layout thrashing. Use will-change property to hint the browser about the elements that will change.

    .playerWrapperV2 {
      will-change: transform, opacity;
    }

Implementing these changes should help improve the performance of the session player UI.

References

/frontend/src/pages/Player/PlayerHook/PlayerState.ts
/frontend/src/pages/Player/SessionView.tsx
/frontend/src/pages/Player/PlayerHook/PlayerHook.tsx

Ask Greptile

@SpennyNDaJets SpennyNDaJets closed this as not planned Won't fix, can't repro, duplicate, stale Sep 12, 2024
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

1 participant