You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Internal performance optimizations have been implemented to significantly reduce overhead when logging is disabled. **No API changes were made** - existing code continues to work unchanged while benefiting from improved performance.
6
+
7
+
## Key Optimizations
8
+
9
+
### 1. Deferred Array Creation
10
+
11
+
Logging methods now avoid the spread operator overhead by deferring array spreading until after level checks pass. When logging is disabled, no arrays are created from the spread operation.
12
+
13
+
### 2. Optimized Cycle Detection
14
+
15
+
The `jsonify` function uses Set-based cycle detection instead of array-based tracking, improving performance from O(n) to O(1) lookups when serializing complex objects with circular references.
16
+
17
+
### 3. LogWriter Level Guards
18
+
19
+
LogWriter implementations check log levels before expensive operations like timestamp generation and color formatting, preventing unnecessary work when logs are disabled.
20
+
21
+
## Performance Characteristics
22
+
23
+
**When log levels are set to WARN/ERROR:**
24
+
- Debug/info calls have near-zero overhead (< 0.001ms per call)
25
+
- Spread operator overhead eliminated for disabled log levels
26
+
- Object serialization optimized with efficient cycle detection
27
+
- Timestamp and formatting operations skipped when not needed
-**Production configuration**: Set system threshold to WARN or ERROR for optimal performance
46
+
-**Complex objects**: Benefits are automatic when logging objects with circular references
47
+
48
+
The optimizations ensure that production applications with logging set to WARN+ experience minimal performance impact from debug/info logging statements.
// if in fact we are building our own logger repo, we need to force this setting because elsewhere we rely on peer dependency
107
107
// if (process && process.env && process.env.FORCE_LOG_WRITER === 'node') {
@@ -115,6 +115,7 @@ export class Log {
115
115
'globalThis.logWriter was not set prior to attempt to write log. Please use @alienfast/logger-browser or @alienfast/logger-node to initialize a writer at the entry point.',
116
116
)
117
117
}
118
+
// Spread the args array only when we actually need to write the log
0 commit comments