perf: Implement critical performance optimizations for hot paths#281
Open
perf: Implement critical performance optimizations for hot paths#281
Conversation
Contributor
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
Contributor
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. |
- 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
previously approved these changes
Feb 19, 2026
Contributor
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 92.87% 92.97% +0.10%
==========================================
Files 78 78
Lines 3564 3603 +39
Branches 904 921 +17
==========================================
+ Hits 3310 3350 +40
+ Misses 254 253 -1
🚀 New features to boost your workflow:
|
Increased timeout for build and unit tests in CI workflow.
nevware21-bot
previously approved these changes
Feb 20, 2026
Contributor
nevware21-bot
left a comment
There was a problem hiding this comment.
Approved by nevware21-bot
nevware21-bot
approved these changes
Feb 20, 2026
Contributor
nevware21-bot
left a comment
There was a problem hiding this comment.
Approved by nevware21-bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.