Skip to content

Conversation

@Ayoub-Mabrouk
Copy link

Reduced redundant typeof operations by caching type checks
and simplified the string length calculation using ternary
operators for improved readability.

Reduced redundant typeof operations by caching type checks
and simplified the string length calculation using ternary
operators for improved readability.
@nodejs-github-bot nodejs-github-bot added assert Issues and PRs related to the assert subsystem. needs-ci PRs that need a full CI run. labels Oct 21, 2025
Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

The calls will likely be inlined during optimization passes in the jit. I am fine with it either way.

@BridgeAR BridgeAR added the request-ci Add this label to start a Jenkins CI on a PR. label Oct 21, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 21, 2025
@nodejs-github-bot
Copy link
Collaborator

@codecov
Copy link

codecov bot commented Oct 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.56%. Comparing base (2fb82c8) to head (54e8e83).
⚠️ Report is 37 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #60331      +/-   ##
==========================================
- Coverage   88.59%   88.56%   -0.03%     
==========================================
  Files         704      704              
  Lines      208474   207800     -674     
  Branches    40067    40035      -32     
==========================================
- Hits       184696   184045     -651     
- Misses      15805    15806       +1     
+ Partials     7973     7949      -24     
Files with missing lines Coverage Δ
lib/internal/assert/assertion_error.js 95.88% <100.00%> (-0.05%) ⬇️

... and 108 files with indirect coverage changes

🚀 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.

Copy link
Member

@ovflowd ovflowd left a comment

Choose a reason for hiding this comment

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

I don't think this PR improves on anything. As @BridgeAR mentioned, these checks get optimized anyays.

IMO, these changes make it harder to read instead of actually easier. I'm -1 with these changes.

Nevertheless, appreciate the contribution 🙇

@Ayoub-Mabrouk
Copy link
Author

I don't think this PR improves on anything. As @BridgeAR mentioned, these checks get optimized anyays.

IMO, these changes make it harder to read instead of actually easier. I'm -1 with these changes.

Nevertheless, appreciate the contribution 🙇

I agree that V8 will optimize repeated typeof checks and that this isn’t a performance-critical hot path, so I’m not claiming measurable speedups here. I mainly extracted the typeof results into named constants (isStrA, isStrE) to:

Avoid repeating the same typeof expression in multiple places,

Make the intent of the string-length adjustment a bit more explicit.

That said, I completely agree that readability and maintainability should come first, especially in core code where future readers matter a lot more than speculative micro-optimizations. If folks feel the original version is clearer, I’m happy to drop or adjust this change—no strong preference here.

🙏 Also, when you have a moment, could you take a look at https://github.com/nodejs/node/pull/61223
I’d really appreciate your insight there as well.

@ovflowd
Copy link
Member

ovflowd commented Dec 31, 2025

That said, I completely agree that readability and maintainability should come first, especially in core code where future readers matter a lot more than speculative micro-optimizations. If folks feel the original version is clearer, I’m happy to drop or adjust this change—no strong preference here.

Yeah, that's my main take, ternary operators can be helpful, but in this case, to my eyes, the older diff is clearer to read and to immediately see what's going on. You're spot on the DX over minimalism here.

🙏 Also, when you have a moment, could you take a look at https://github.com/nodejs/node/pull/61223

Of couse :)

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

Labels

assert Issues and PRs related to the assert subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants