perf: Implement critical performance optimizations for hot paths#281
perf: Implement critical performance optimizations for hot paths#281
Conversation
nev21
commented
Feb 19, 2026
- Remove objDefine getters from hot path properties (opts, value, orgArgs)
- Change property accessors from getter functions to direct assignments
- Extract and export _extractArgs() for cleaner argument handling
- Reorder formatters by probability (String, Object, Array first)
- Add configurable prototype chain depth limiting (maxProtoDepth: 4)
- Centralize formatting logic in format manager with convenience method
There was a problem hiding this comment.
Pull request overview
This PR introduces performance-focused refactors across core assertion hot paths, primarily by centralizing formatting in the format manager, reducing getter-based property access, and extracting shared argument parsing logic.
Changes:
- Move/centralize value formatting into
formatMgr.format()and update callers to route formatting through scope context. - Extract and export
_extractArgs()to standardize assertion argument/message handling and add targeted unit tests. - Optimize default formatting behavior (formatter ordering, prototype-chain key collection depth limiting via
maxProtoDepth).
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| core/test/src/support/checkError.ts | Update stack-frame error message formatting to use scope-context-based _formatValue() signature. |
| core/test/src/internal/formatManager.test.ts | Add tests for new formatMgr.format() convenience method behavior (including circular handling & finalize option). |
| core/test/src/assert/extractArgs.test.ts | Add unit coverage for _extractArgs() argument/message extraction behavior and edge cases. |
| core/src/internal/formatManager.ts | Add format() API, move formatting/circular/finalize logic into manager, and bind formatting to config instance. |
| core/src/internal/_formatValue.ts | Simplify _formatValue() to delegate to ctx.opts.$ops.formatMgr.format(). |
| core/src/internal/_defaultFormatters.ts | Reorder default formatters and add prototype-chain depth limiting when collecting object keys. |
| core/src/interface/IFormatterOptions.ts | Add maxProtoDepth configuration option documentation. |
| core/src/interface/IFormatManager.ts | Add format(value) to the format manager interface. |
| core/src/config/defaultConfig.ts | Provide default format.maxProtoDepth value. |
| core/src/config/config.ts | Wire config-created format manager with config instance and add $ops.toJSON to avoid exposing internals during serialization. |
| core/src/assert/scopeContext.ts | Switch hot-path properties to direct value descriptors and update token formatting to pass full scope context. |
| core/src/assert/funcs/equal.ts | Update _formatValue() call to new signature (scope context instead of config). |
| core/src/assert/assertionError.ts | Update _formatValue() calls inside error property formatting to new signature. |
| core/src/assert/assertScope.ts | Replace getter-based scope context property with direct value descriptor and update it on context changes. |
| core/src/assert/assertClass.ts | Extract and export _extractArgs() and refactor proxy assertion function to use it. |
| core/src/assert/adapters/exprAdapter.ts | Update _formatValue() usage to new signature. |
nevware21-bot
left a comment
There was a problem hiding this comment.
Approved by nevware21-bot
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #281 +/- ##
=======================================
Coverage 95.29% 95.30%
=======================================
Files 137 137
Lines 6313 6388 +75
Branches 1653 1640 -13
=======================================
+ Hits 6016 6088 +72
- Misses 297 300 +3
🚀 New features to boost your workflow:
|
nevware21-bot
left a comment
There was a problem hiding this comment.
Approved by nevware21-bot
nevware21-bot
left a comment
There was a problem hiding this comment.
Approved by nevware21-bot
- Remove objDefine getters from hot path properties (opts, value, orgArgs) - Change property accessors from getter functions to direct assignments - Extract and export _extractArgs() for cleaner argument handling - Reorder formatters by probability (String, Object, Array first) - Add configurable prototype chain depth limiting (maxProtoDepth: 4) - Centralize formatting logic in format manager with convenience method
nevware21-bot
left a comment
There was a problem hiding this comment.
Approved by nevware21-bot