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:
| Interval | Use Case | Bandwidth |
|---|---|---|
| 10-20 seconds | Competitive games where presence is critical | High |
| 30-60 seconds | Most multiplayer games (recommended) | Medium |
| 120+ seconds | Casual games, low-bandwidth situations | Low |
| 0 (disabled) | Manual refresh only | Lowest |
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
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_idfriend_requests.sender_idfriend_requests.receiver_idinvitations.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
- Use WebSocket (Node.js server) for real-time games
- Set RefreshInterval to 30-60 seconds for most games
- Use events to update only changed UI elements
- Set appropriate limits for MaxFriends based on your game's social features
- Profile your specific use case with Unity Profiler and network analytics