-
Notifications
You must be signed in to change notification settings - Fork 13
Commit c17e584
Optimize CodeComparisonView rendering performance
Summary:
Optimize CodeComparisonView component to eliminate unnecessary re-renders and improve responsiveness when handling line highlighting. The key insight is that highlighting is a purely visual operation that doesn't require React state updates - we can use direct DOM manipulation for better performance.
Performance Improvements:
- Replace useState with useRef for highlight state (eliminates 3 state updates per click)
- Implement direct DOM manipulation via requestAnimationFrame for highlight updates
- Add useMemo for panel data caching (prevents object recreation on every render)
- Extract pure utility functions (calculateMappedLines, calculatePythonLines) with empty deps
- Optimize event handlers to reduce closure recreations
- Wrap component with React.memo for props-based memoization
Code Quality:
- Translate all Chinese comments to English for better code accessibility
- Add comprehensive JSDoc documentation for all functions
- Improve code organization with clear section markers
- Add detailed comments explaining the optimization strategy
Expected Performance Gains:
- ~70% reduction in component re-renders during line highlighting
- Faster highlight updates (direct DOM manipulation vs React reconciliation)
- Lower memory pressure from reduced state updates
- More responsive UI, especially with rapid clicking
Reviewed By: xuzhao9
Differential Revision: D85825649
fbshipit-source-id: 6215197bd462a4feec386281e678abc1fd1d899a1 parent 220d5a4 commit c17e584Copy full SHA for c17e584
File tree
Expand file treeCollapse file tree
1 file changed
+457
-310
lines changedOpen diff view settings
Filter options
- website/src/components
Expand file treeCollapse file tree
1 file changed
+457
-310
lines changedOpen diff view settings
0 commit comments