0
0
Unityframework~8 mins

Lobby and matchmaking basics in Unity - Performance & Optimization

Choose your learning style9 modes available
Performance: Lobby and matchmaking basics
MEDIUM IMPACT
This concept affects the initial load time and responsiveness of multiplayer game sessions by managing player grouping and connection setup.
Grouping players into a game session quickly and smoothly
Unity
async Task StartMatchmakingAsync() {
  await ConnectAllPlayersAsync(allPlayers);
  UpdateUIOnce();
}
Batch connecting players asynchronously and updating UI once reduces main thread blocking and reflows.
📈 Performance GainSingle UI update and non-blocking matchmaking improves responsiveness and reduces input delay.
Grouping players into a game session quickly and smoothly
Unity
void StartMatchmaking() {
  foreach (var player in allPlayers) {
    ConnectPlayerToSession(player);
    UpdateUI();
  }
}
Connecting players one by one and updating UI each time causes multiple reflows and UI thread blocking.
📉 Performance CostTriggers multiple UI updates and blocks main thread, causing input lag and slow matchmaking.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Sequential player connection with UI update per playerHigh (multiple updates)Multiple reflowsHigh paint cost[X] Bad
Batch player connection with single UI updateLow (single update)Single reflowLow paint cost[OK] Good
Rendering Pipeline
Lobby and matchmaking operations affect the UI rendering pipeline by triggering layout recalculations and paint operations when player lists or statuses update.
Layout
Paint
Composite
⚠️ BottleneckLayout recalculation caused by frequent UI updates during matchmaking
Core Web Vital Affected
INP
This concept affects the initial load time and responsiveness of multiplayer game sessions by managing player grouping and connection setup.
Optimization Tips
1Batch UI updates during matchmaking to reduce layout recalculations.
2Use asynchronous operations to avoid blocking the main thread.
3Minimize frequent DOM or UI changes to improve input responsiveness.
Performance Quiz - 3 Questions
Test your performance knowledge
What is a main performance issue when updating the lobby UI after each player joins individually?
AMultiple layout recalculations causing input lag
BToo few DOM nodes created
CNo impact on rendering performance
DFaster rendering due to incremental updates
DevTools: Performance
How to check: Record a session during matchmaking, look for long tasks and frequent layout recalculations in the flame chart.
What to look for: Look for reduced main thread blocking and fewer layout recalculations indicating better matchmaking performance.