(
baseTimeoutMs: number,
dims: { width: number; height: number },
)
| 283 | * for tests. |
| 284 | */ |
| 285 | export function scaleProtocolTimeoutForComposition( |
| 286 | baseTimeoutMs: number, |
| 287 | dims: { width: number; height: number }, |
| 288 | ): number { |
| 289 | const { width, height } = dims; |
| 290 | if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0) { |
| 291 | return baseTimeoutMs; |
| 292 | } |
| 293 | const factor = (width * height) / PROTOCOL_TIMEOUT_REFERENCE_PIXELS; |
| 294 | if (factor <= 1) return baseTimeoutMs; |
| 295 | const scaled = Math.ceil(baseTimeoutMs * factor); |
| 296 | // Ceiling is `max(base, MAX)` so an explicit base above the ceiling is never |
| 297 | // lowered (preserves the "only ever raise" contract for all callers). |
| 298 | const ceiling = Math.max(baseTimeoutMs, MAX_SCALED_PROTOCOL_TIMEOUT_MS); |
| 299 | return Math.min(ceiling, Math.max(baseTimeoutMs, scaled)); |
| 300 | } |
| 301 | |
| 302 | function memoryAdaptiveCacheLimit(): number { |
| 303 | const total = getSystemTotalMb(); |
no outgoing calls
no test coverage detected