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

레이아웃 컴포넌트 리렌더링 최적화 #164

Closed
5 tasks
kwaksj329 opened this issue Nov 29, 2024 · 0 comments · Fixed by #194
Closed
5 tasks

레이아웃 컴포넌트 리렌더링 최적화 #164

kwaksj329 opened this issue Nov 29, 2024 · 0 comments · Fixed by #194
Assignees
Labels
🔨 Refactor Code Refactoring
Milestone

Comments

@kwaksj329
Copy link
Member

kwaksj329 commented Nov 29, 2024

제목: 🔄 전역 상태 변경에 따른 불필요한 리렌더링 최적화

📂 구현 기능

레이아웃 컴포넌트와 웹소켓 상태 변경 시 발생하는 불필요한 리렌더링을 포함하여, 애플리케이션 전반의 리렌더링 패턴을 분석하고 최적화합니다.

📝 상세 작업 내용

  • 전반적인 리렌더링 패턴 분석
    • React DevTools Profiler를 사용한 전체 컴포넌트 리렌더링 추적
    • 컴포넌트별 리렌더링 빈도 및 원인 분석
    • 병목 지점 식별
  • GameLayout 컴포넌트의 리렌더링 패턴 분석
    • 웹소켓 연결 상태 변경 시 리렌더링 추적
    • Zustand selector 사용 패턴 분석
    • 리렌더링 원인이 되는 상태 의존성 식별
  • 웹소켓 상태 관리 구조 리팩토링
    • Zustand 스토어 구조 최적화 (상태 분리 검토)
    • selector 함수 메모이제이션 적용
    • 불필요한 상태 구독 제거
  • 컴포넌트별 최적화 적용
    • 과도한 리렌더링이 발생하는 컴포넌트 식별
    • React.memo와 메모이제이션 훅 적용
    • Props drilling 개선
    • 컴포넌트 분할 및 구조 개선
  • 성능 측정 및 개선 검증
    • 개선 전/후 성능 비교 분석
    • 사용자 경험 개선 정도 측정

🔆 참고 사항

  • Zustand 공식 문서의 성능 최적화 가이드 참고
  • React DevTools Profiler를 활용한 성능 측정
  • React 렌더링 최적화 best practices 적용
  • Chrome Performance 탭을 활용한 전반적인 성능 프로파일링

⏰ 예상 작업 시간

  • 전체 분석 및 설계: 3시간
  • 수정 사항 구현: 3시간
    총 6시간 소요 예상
@kwaksj329 kwaksj329 self-assigned this Nov 29, 2024
@kwaksj329 kwaksj329 added the 🔨 Refactor Code Refactoring label Nov 29, 2024
@rhino-ty rhino-ty assigned rhino-ty and unassigned kwaksj329 Dec 2, 2024
@rhino-ty rhino-ty changed the title 레이아웃 컴포넌트 리렌더링 방지 레이아웃 컴포넌트 리렌더링 최적화 Dec 2, 2024
@rhino-ty rhino-ty added this to the Week 6 milestone Dec 2, 2024
rhino-ty added a commit that referenced this issue Dec 4, 2024
…ion and modular architecture (#194)

* chore: Remove @tanstack/react-query

* refactor: Extract checkProduction logic from api.config.ts

* refactor: Optimize re-rendering with individual selectors and memo

- Wrap PlayerCardList component with memo to prevent unnecessary re-renders
- Replace object destructuring from useGameSocketStore with individual selectors
- Split store access into separate selectors for better performance:
 - players
 - hostId
 - roundAssignedRole
 - currentPlayerId
- Maintain same functionality while reducing re-renders from unrelated state changes

* refactor(Chat): split Chat component into modular components and optimize performance

- Decompose monolithic Chat component into smaller focused components:
 - ChatContainer: Top-level socket management
 - ChatList: Message display and scroll management
 - ChatInput: Message input and submission
 - ChatBubble: Individual message UI
- Add memo to all components to prevent unnecessary re-renders
- Implement individual selectors for Zustand store access
- Enhance useDrawingSocket hook with submitDrawing event handler
- Improve code organization and separation of concerns

* fix: Modify mobile-web-app-capable

* refactor: Optimize performance of Setting component

- Optimize state subscription
  - Prevent unnecessary re-renders by separating useGameSocketStore selectors
  - Change to individually subscribe only to roomSettings and isHost states
- Component memoization
  - Apply memo to Setting component
  - Memoize handleSettingChange callback function with useCallback
- Improve component structure
  - Separate concerns by extracting SettingContent component
  - Define RoomSettingItem type and separate setting constants
  - Reduce unnecessary JSX nesting
- Enhance type safety
  - Add SettingKey type alias
  - Export RoomSettingItem interface for reusability

* Merge branch 'develop' into refactor/#164

* feat: Enhance SHORTCUT_KEYS with additional information and Korean support

- Rename SHORTCUT_KEY to SHORTCUT_KEYS for consistency
- Add description for each shortcut
- Include alternative keys for most shortcuts
- Add Korean character alternatives for game-related shortcuts
- Group shortcuts by category (settings and game-related)
- Change number keys for dropdown settings (1, 2, 3 instead of q, w, e)
- Use 'as const' for type safety

* feat: Implement useShortcuts custom hook for advanced shortcut handling

- Create useShortcuts custom hook for managing keyboard shortcuts
- Add support for main and alternative keys defined in SHORTCUT_KEYS
- Implement shortcut disabling for input elements (input, textarea, select)
- Allow dynamic configuration of shortcuts with action and disabled state
- Prevent default browser behavior when shortcut is triggered
- Ensure proper cleanup of event listener on component unmount

* feat: Apply useShortcuts hook across components for shortcut functionality

- Add useShortcuts hook
  • ChatInput
  • InviteButton
  • StartButton
  • Setting
  • SettingItem
  • Dropdown
- Integrate useShortcuts in useDropdown and useStartButton hooks
- Update ROOM_SETTINGS to include shortcutKey for each setting item
- Replace individual keydown event listeners with useShortcuts hook
- Enhance code consistency and maintainability across the application

* refactor: Remove console.log on useDrawingSocket, createSocket

* refactor: Implement zustand selectors across components and hooks

- Replace direct zustand store access with selectors
  • InviteButton
  • NavigationModal
  • RoleModal
  • RoundEndModal
  • QuizStage
  • ToastContainer
  • BrowserNavigationGuard
  • GameHeader
  • GameLayout
- Update hooks to use zustand selectors
  • useCreateRoom
  • useTimer
  • useDrawingState
  • useChatSocket
  • useDrawingSocket
  • useGameSocket
- Improve performance by minimizing unnecessary re-renders
- Enhance code readability and maintainability

* fix: Resolve timer decrement issue in game by updating useTimer hook's dependency array and interval management

* feat: Extract Timer store from gameSocket.store.ts to reduce unnecessary re-renders

- Created a dedicated Timer store using Zustand to manage timer states.
- Implemented actions for updating, decreasing, and resetting timers.
- Ensured that the Timer store operates independently to enhance performance and maintainability.

* feat: Modify Timer logic

- Changed the source of the timer logic from the game socket store to the timer store
- Improved performance by preventing unnecessary re-renders with an independent timer store

* feat: Add win or loss sound

* style: Modify Game Layout min-height to 45rem

* style: Modify volume input from vertical to horizontal

- Change the volume input orientation from vertical to horizontal
- Remove vertical-related styling and logic
- Adjust layout for horizontal display

* feat: Add loading state and message when game start button clicked

* feat: Add roundLoss animation to RoundEndModal

* refactor: Delete SHORTCUT_KEY because it's useless

* refactor: Optimize timer management in useTimer hook

- Simplify dependency array in useEffect to prevent unnecessary re-renders
- Improve timer interval handling to avoid creating/clearing intervals on every render

* fix: Add z-index to GameHeader for proper layering

- Apply z-10 class to GameHeader component to ensure it appears above background elements
- Resolve potential overlap issues with other page elements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment