Implement performance optimizations for chart updates: adaptive throttling, data sampling, dynamic bin adjustment, and request batching
This commit is contained in:
@@ -374,6 +374,16 @@ def get_wealth_distribution(simulation_id: str):
|
||||
if num_bins < 1 or num_bins > 50:
|
||||
num_bins = 10 # Default to 10 bins
|
||||
|
||||
# Optimize bin count based on agent count for better performance
|
||||
agent_count = len(simulation.agents) if simulation.agents else 0
|
||||
if agent_count > 0:
|
||||
# Reduce bin count for small agent populations to improve performance
|
||||
if agent_count < 50 and num_bins > agent_count // 2:
|
||||
num_bins = max(3, agent_count // 2)
|
||||
# Cap bin count for very large simulations to prevent performance issues
|
||||
elif agent_count > 1000 and num_bins > 25:
|
||||
num_bins = 25
|
||||
|
||||
# Get histogram data
|
||||
bin_labels, bin_counts = simulation.get_wealth_histogram(num_bins)
|
||||
|
||||
|
Reference in New Issue
Block a user