perf: optimize min/max in hot code path