#!/bin/bash

# Calculate UV_THREADPOOL_SIZE based on CPU core count
# Formula: nproc * 32, clamped between MIN and MAX

MIN_THREADPOOL_SIZE=64
MAX_THREADPOOL_SIZE=384
MULTIPLIER=32

# Get the number of CPU cores
core_count=$(nproc)

# Calculate threadpool size
threadpool_size=$((core_count * MULTIPLIER))

# Clamp to min/max
if [[ "$threadpool_size" -lt "$MIN_THREADPOOL_SIZE" ]]; then
  echo "$MIN_THREADPOOL_SIZE"
elif [[ "$threadpool_size" -gt "$MAX_THREADPOOL_SIZE" ]]; then
  echo "$MAX_THREADPOOL_SIZE"
else
  echo "$threadpool_size"
fi
