Performance Tips

This page covers best practices for optimizing the Universal Friend List system for better performance and reduced bandwidth usage.

Refresh Interval Settings

Choose the Right Refresh Interval

The RefreshInterval setting controls how often the friend list is automatically refreshed:

IntervalUse CaseBandwidth
10-20 secondsCompetitive games where presence is criticalHigh
30-60 secondsMost multiplayer games (recommended)Medium
120+ secondsCasual games, low-bandwidth situationsLow
0 (disabled)Manual refresh onlyLowest

Disable Auto-Refresh When Possible

If your game doesn't need real-time presence updates, set RefreshInterval to 0 and call RefreshFriendList() only when the user opens the friend UI.

WebSocket vs HTTP Polling

Use WebSocket When Possible

WebSocket connections are more efficient than HTTP polling:

  • WebSocket: Single persistent connection, instant updates, lower bandwidth
  • HTTP Polling: New connection each request, request/response overhead
Recommendation: Use WebSocket (Node.js server) for production games. Use HTTP polling (PHP server) only for development or when WebSocket hosting isn't available.

Polling Optimization

If you must use HTTP polling:

  • Increase PollingInterval to reduce requests (30-60 seconds is reasonable)
  • Refresh only when user is looking at the friend list
  • Use manual refresh instead of automatic polling

UI Optimization

List Virtualization

For users with many friends, consider implementing list virtualization in your custom UI. Only render visible friend items rather than the entire list.

Event-Driven Updates

The friend system uses events for updates. Ensure your UI only updates the specific changed elements rather than refreshing the entire list:

// Good: Update only changed item
friendManager.OnFriendStatusChanged += (friend) => {
    UpdateFriendItem(friend); // Update single item
};

// Avoid: Complete list refresh on any change
friendManager.OnFriendsListUpdated += (list) => {
    RebuildEntireList(); // Inefficient
};

Server-Side Optimization

Database Indexing

For production servers, ensure database indexes exist on frequently queried columns:

  • friendships.user_id
  • friend_requests.sender_id
  • friend_requests.receiver_id
  • invitations.receiver_id

Connection Pooling

For Node.js, ensure database connection pooling is enabled. For PHP with MySQL, use PDO persistent connections if available.

Redis Caching

For high-scale deployments, consider adding Redis to cache friend lists and reduce database load. The Node.js server architecture supports this as an extension point.

Bandwidth Optimization

Minimize Request Frequency

  • Use longer refresh intervals for presence updates
  • Batch multiple operations when possible
  • Avoid unnecessary RefreshFriendList calls

Compress Data

If running your own custom server, enable gzip compression on API responses to reduce bandwidth usage.

Memory Optimization

Friend List Limits

Set MaxFriends and MaxBlockedUsers to reasonable limits for your game. This prevents unbounded memory growth:

  • Casual games: 50-100 friends
  • Social games: 100-500 friends
  • Community games: 500-1000 friends

Disable Persistence if Not Needed

If you don't need to persist friend lists between sessions, disable PersistFriendList and PersistBlockList to save memory and storage.

Quick Recommendations

  1. Use WebSocket (Node.js server) for real-time games
  2. Set RefreshInterval to 30-60 seconds for most games
  3. Use events to update only changed UI elements
  4. Set appropriate limits for MaxFriends based on your game's social features
  5. Profile your specific use case with Unity Profiler and network analytics