perf: reduce message delivery latency across all connection scenarios
Surgical optimizations to eliminate message delivery delays after QR scan, pm2 restart, and code updates: Buffer/Flush: - bufferTimeoutMs: 5s→3s (safety auto-flush cap) - maxBufferTimeoutMs: 8s→3s (adaptive timeout ceiling) - flushDebounceMs: 100ms→10ms (createBufferedFunction debounce) - OFFLINE_BUFFER_TIMEOUT_MS: 5s→2s (first-connection buffer) - AwaitingInitialSync: 4s→2s (history sync wait) Mutex parallelism: - receiptMutex: global→keyed by remoteJid (parallel receipt processing) - notificationMutex: global→keyed by remoteJid (parallel notification processing) Delay reduction: - retryRequestDelayMs: 250ms→150ms - transactionOpts.delayBetweenTriesMs: 3s→1s Offline processing: - BATCH_SIZE: 10→25 (fewer event loop yields) Expected impact: QR scan worst-case 8s→2s, pm2 restart 100ms→10ms. All existing customizations preserved (Circuit Breaker, Prometheus, TcToken, CTWA Recovery, sanitizeCallerPn, Session Cleanup, LID Mapping, Identity Key cache, clearRoutingInfoOnStart, wasm-bridge). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -57,12 +57,12 @@ export function loadBufferConfig(): BufferConfig {
|
||||
// perf(inbound-latency): reduced from 15s → 5s so the safety auto-flush fires sooner.
|
||||
// processNodeWithBuffer always calls ev.flush() explicitly (no-op for this timer),
|
||||
// but socket.ts's offline-phase buffer and any stalled buffer benefit from the lower cap.
|
||||
bufferTimeoutMs: parseInt(process.env.BAILEYS_BUFFER_TIMEOUT_MS || '5000', 10),
|
||||
bufferTimeoutMs: parseInt(process.env.BAILEYS_BUFFER_TIMEOUT_MS || '3000', 10),
|
||||
minBufferTimeoutMs: parseInt(process.env.BAILEYS_BUFFER_MIN_TIMEOUT_MS || '1000', 10),
|
||||
maxBufferTimeoutMs: parseInt(process.env.BAILEYS_BUFFER_MAX_TIMEOUT_MS || '8000', 10),
|
||||
maxBufferTimeoutMs: parseInt(process.env.BAILEYS_BUFFER_MAX_TIMEOUT_MS || '3000', 10),
|
||||
maxHistoryCacheSize: parseInt(process.env.BAILEYS_BUFFER_MAX_HISTORY_CACHE || '10000', 10),
|
||||
maxBufferSize: parseInt(process.env.BAILEYS_BUFFER_MAX_SIZE || '5000', 10),
|
||||
flushDebounceMs: parseInt(process.env.BAILEYS_BUFFER_FLUSH_DEBOUNCE_MS || '100', 10),
|
||||
flushDebounceMs: parseInt(process.env.BAILEYS_BUFFER_FLUSH_DEBOUNCE_MS || '10', 10),
|
||||
enableAdaptiveTimeout: process.env.BAILEYS_BUFFER_ADAPTIVE_TIMEOUT !== 'false',
|
||||
enableMetrics: process.env.BAILEYS_BUFFER_METRICS === 'true' || process.env.BAILEYS_PROMETHEUS_ENABLED === 'true',
|
||||
lruCleanupRatio: parseFloat(process.env.BAILEYS_BUFFER_LRU_CLEANUP_RATIO || '0.2'),
|
||||
|
||||
Reference in New Issue
Block a user