Skip to content

perf: Implement critical performance optimizations for hot paths#281

Open
nev21 wants to merge 6 commits intomainfrom
nev21/perf
Open

perf: Implement critical performance optimizations for hot paths#281
nev21 wants to merge 6 commits intomainfrom
nev21/perf

Conversation

@nev21
Copy link
Contributor

@nev21 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

@nev21 nev21 added this to the 0.1.8 milestone Feb 19, 2026
Copilot AI review requested due to automatic review settings February 19, 2026 06:06
@nev21 nev21 requested review from a team as code owners February 19, 2026 06:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated no new comments.

@nev21 nev21 enabled auto-merge (squash) February 19, 2026 07:07
nevware21-bot
nevware21-bot previously approved these changes Feb 19, 2026
Copy link
Contributor

@nevware21-bot nevware21-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved by nevware21-bot

@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

❌ Patch coverage is 92.50000% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.97%. Comparing base (363bc9f) to head (4914951).

Files with missing lines Patch % Lines
core/src/internal/formatManager.ts 91.35% 7 Missing ⚠️
core/src/assert/assertionError.ts 33.33% 2 Missing ⚠️
core/src/assert/scopeContext.ts 50.00% 2 Missing ⚠️
core/src/assert/funcs/equal.ts 0.00% 1 Missing ⚠️
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     
Files with missing lines Coverage Δ
core/src/assert/adapters/exprAdapter.ts 86.53% <100.00%> (ø)
core/src/assert/assertClass.ts 96.45% <100.00%> (+2.64%) ⬆️
core/src/assert/assertScope.ts 96.15% <100.00%> (-0.21%) ⬇️
core/src/config/config.ts 97.01% <100.00%> (+0.13%) ⬆️
core/src/config/defaultConfig.ts 100.00% <ø> (ø)
core/src/internal/_defaultFormatters.ts 91.21% <100.00%> (+0.13%) ⬆️
core/src/internal/_formatValue.ts 100.00% <100.00%> (+9.37%) ⬆️
core/src/assert/funcs/equal.ts 88.11% <0.00%> (ø)
core/src/assert/assertionError.ts 88.05% <33.33%> (ø)
core/src/assert/scopeContext.ts 90.36% <50.00%> (-0.34%) ⬇️
... and 1 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

nevware21-bot
nevware21-bot previously approved these changes Feb 20, 2026
Copy link
Contributor

@nevware21-bot nevware21-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved by nevware21-bot

Copy link
Contributor

@nevware21-bot nevware21-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved by nevware21-bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments