Hypothesis
The manual format scanner still uses args.splice(index, 1) to remove inlined formatter args. splice is O(n) per call and shifts remaining elements. Building a new output array in one pass avoids this mutation cost.
Rationale
Current code in the format scanner (common.js) does args.splice(index, 1) each time a formatter is inlined. For messages with multiple formatters (e.g. 'request %s took %dms' has 2 formatters), splice runs twice, each time shifting remaining elements. The bench's %s/%d call has 2 format specifiers, and %O has 1.
Instead: build a newArgs array. Start with the rebuilt format string as newArgs[0]. Then append only the args that were NOT consumed by formatters. This is O(n) total instead of O(n) per formatter.
Scope
- src/common.js: modify the manual format scanner to build a new array rather than splicing the existing args array
- Pass newArgs to formatArgs and logFn instead of the mutated args
Expected impact
Small to moderate. Reduces per-formatter overhead from O(n) splice to O(1) append. Most impactful on the %s/%d call which has 2 formatters.
Risks
Must ensure all args are correctly carried through. The formatArgs function and logFn receive the new array. Non-formatter args (consumed by util.formatWithOptions) must remain in order.
Hypothesis
The manual format scanner still uses args.splice(index, 1) to remove inlined formatter args. splice is O(n) per call and shifts remaining elements. Building a new output array in one pass avoids this mutation cost.
Rationale
Current code in the format scanner (common.js) does args.splice(index, 1) each time a formatter is inlined. For messages with multiple formatters (e.g. 'request %s took %dms' has 2 formatters), splice runs twice, each time shifting remaining elements. The bench's %s/%d call has 2 format specifiers, and %O has 1.
Instead: build a newArgs array. Start with the rebuilt format string as newArgs[0]. Then append only the args that were NOT consumed by formatters. This is O(n) total instead of O(n) per formatter.
Scope
Expected impact
Small to moderate. Reduces per-formatter overhead from O(n) splice to O(1) append. Most impactful on the %s/%d call which has 2 formatters.
Risks
Must ensure all args are correctly carried through. The formatArgs function and logFn receive the new array. Non-formatter args (consumed by util.formatWithOptions) must remain in order.