Skip to content

Conversation

@gurgunday
Copy link
Member

@gurgunday gurgunday commented Apr 22, 2025

Merges the Channel and ActiveChannel classes

I think dynamically modifying prototypes is not good practice and leads to unnecessary duplication

We can simply use a single class with an internal state

It also replaces the good ol' _ properties with private properties

We should be able to get this into v24

@nodejs-github-bot nodejs-github-bot added diagnostics_channel Issues and PRs related to diagnostics channel needs-ci PRs that need a full CI run. labels Apr 22, 2025
@gurgunday gurgunday added needs-ci PRs that need a full CI run. and removed needs-ci PRs that need a full CI run. labels Apr 22, 2025
@codecov
Copy link

codecov bot commented Apr 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.27%. Comparing base (e9b286c) to head (90cb7d0).
⚠️ Report is 1084 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #57977   +/-   ##
=======================================
  Coverage   90.27%   90.27%           
=======================================
  Files         630      630           
  Lines      186165   186130   -35     
  Branches    36485    36477    -8     
=======================================
- Hits       168064   168037   -27     
  Misses      10974    10974           
+ Partials     7127     7119    -8     
Files with missing lines Coverage Δ
lib/diagnostics_channel.js 100.00% <100.00%> (+0.91%) ⬆️

... and 35 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.

@BridgeAR
Copy link
Member

@gurgunday this was intentionally separated for performance reasons. Now it has to do the checks that it formerly could just skip. It's probably not a huge overhead but it should be measurable.

@gurgunday
Copy link
Member Author

I see, are you down to merging if there are no regressions? I'm not really convinced a boolean check is slower than changing the prototype dynamically

@gurgunday gurgunday added the needs-benchmark-ci PR that need a benchmark CI run. label Apr 22, 2025
#maybeDeactivate() {
if (this.#active && !this.#subscribers.length && !this.#stores.size) {
this.#active = false;
this.#subscribers = undefined;
Copy link
Member

Choose a reason for hiding this comment

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

This changes this._subscribers to this.#subscribers which is a breaking change.

@anonrig anonrig added the semver-major PRs that contain breaking changes and should be released in the next major version. label Apr 22, 2025
@gurgunday
Copy link
Member Author

Added a benchmark that tests various scenarios

@jasnell jasnell requested a review from Qard April 23, 2025 02:15
@Qard
Copy link
Member

Qard commented Apr 23, 2025

I would very much want to see benchmark results before accepting this change.

As @BridgeAR said, this was intentionally designed this way. The reason being because it shifts the cost to occur only when a subscribe/unsubscribe happens which is far less frequent than a publish or runStores. It is specifically designed to do the least amount of work at publish time as possible to allow it to be called liberally without worry about the cost, especially when there are no subscribers.

When I wrote this initially, I tested several different structures including an internally-switched model like this. The prototype switch was the fastest by far, it was not even close.

There are also some changes here beyond just the internal-switching structure that I would be concerned about: private fields, last I checked, were still notably slower, and object destructuring is also slower than the manual extraction it was doing previously.

@gurgunday gurgunday closed this Sep 22, 2025
@gurgunday gurgunday deleted the diagnostic-refactor branch September 22, 2025 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostics_channel Issues and PRs related to diagnostics channel needs-benchmark-ci PR that need a benchmark CI run. needs-ci PRs that need a full CI run. semver-major PRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants