Skip to content

Conversation

gurgunday
Copy link
Member

@gurgunday gurgunday commented Oct 5, 2025

Now that the Priority Queue heap is a PACKED array, we can safely check if the value is undefined instead of nullish here

Relevant code:

#heap = [undefined, undefined];
#setPosition;
#size = 0;
constructor(comparator, setPosition) {
if (comparator !== undefined)
this.#compare = comparator;
if (setPosition !== undefined)
this.#setPosition = setPosition;
}
insert(value) {
const heap = this.#heap;
const pos = ++this.#size;
heap[pos] = value;
this.percolateUp(pos);
}
peek() {
return this.#heap[1];
}

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout. labels Oct 5, 2025
Copy link

codecov bot commented Oct 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.52%. Comparing base (32851f3) to head (0c18b90).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #60124      +/-   ##
==========================================
- Coverage   88.53%   88.52%   -0.02%     
==========================================
  Files         703      703              
  Lines      207833   207833              
  Branches    40014    40011       -3     
==========================================
- Hits       184011   183981      -30     
- Misses      15821    15859      +38     
+ Partials     8001     7993       -8     
Files with missing lines Coverage Δ
lib/internal/timers.js 99.58% <100.00%> (ø)

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

@aduh95
Copy link
Contributor

aduh95 commented Oct 6, 2025

But why?

@gurgunday
Copy link
Member Author

The only values in the queue are undefined and TimersList, checking explicitly against undefined communicates this more clearly - I myself thought null could somehow be in the queue when I first read this part

We do the same when shifting the FixedQueue at task_queues, where only null and TickObject are in the list :

while ((tock = queue.shift()) !== null) {

I'm trying to align the various queue codes and their usage a little bit, but I can close the PR if you think nullish check is still fine

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

Labels

needs-ci PRs that need a full CI run. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants