Skip to content

Conversation

gurgunday
Copy link
Member

@gurgunday gurgunday commented Sep 27, 2025

Further improves performance and fixes leftover issues from my last PR

Benchmarks:

main

node % ./node benchmark/run.js --filter priority util

util/priority-queue.js
util/priority-queue.js n=100000: 6,676,867.584962973

branch

node % ./node benchmark/run.js --filter priority util

util/priority-queue.js
util/priority-queue.js n=100000: 6,854,890.535966754

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Sep 27, 2025
Copy link

codecov bot commented Sep 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.45%. Comparing base (79f1999) to head (f980885).
⚠️ Report is 37 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #60039      +/-   ##
==========================================
+ Coverage   88.43%   88.45%   +0.01%     
==========================================
  Files         703      703              
  Lines      207805   207800       -5     
  Branches    40026    40022       -4     
==========================================
+ Hits       183780   183801      +21     
+ Misses      16012    15979      -33     
- Partials     8013     8020       +7     
Files with missing lines Coverage Δ
lib/internal/priority_queue.js 100.00% <100.00%> (+0.80%) ⬆️

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

@gurgunday gurgunday added request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Sep 27, 2025
@gurgunday
Copy link
Member Author

gurgunday commented Sep 28, 2025

const pos = ++this.#size;
heap[pos] = value;
if (heap.length === pos)
heap.length *= 2;

This was dead code before, the check never worked

Example coverage form another PR: https://app.codecov.io/gh/nodejs/node/pull/60060/blob/lib/internal/priority_queue.js?dropdown=coverage#L32

@BridgeAR
Copy link
Member

Benchmark https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1737/

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

CI: https://ci.nodejs.org/job/node-test-pull-request/69438/

@gurgunday gurgunday added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Sep 29, 2025
@gurgunday
Copy link
Member Author

gurgunday commented Sep 30, 2025

@aduh95 can you also take a look, I missed these in my last PR

@gurgunday gurgunday changed the title lib: priority_queue pre-grow array and avoid holey reads lib: increase coverage in priority_queue Sep 30, 2025
@gurgunday
Copy link
Member Author

@aduh95 PTAL, it's actually faster without the manual array resizing in modern node (V8 does it anyway)

So we just removed the dead code and made it packed (assigning to arr[length] keeps it packed)

@gurgunday
Copy link
Member Author

@BridgeAR you can run the priority queue benchmark again by the way

This was faster for me locally

@aduh95
Copy link
Contributor

aduh95 commented Oct 3, 2025

Started a benchmark including the upcoming V8 update: https://github.com/aduh95/node/actions/runs/18221639411

EDIT: seems to be (significantly) faster across the board 🚀

@aduh95
Copy link
Contributor

aduh95 commented Oct 3, 2025

Can you update the commit message? I don't think this has anything to do with coverage, instead you can use something like lib: optimize priority queue.

@gurgunday gurgunday changed the title lib: increase coverage in priority_queue @gurgunday lib: optimize priority queue Oct 3, 2025
@gurgunday gurgunday changed the title @gurgunday lib: optimize priority queue lib: optimize priority queue Oct 3, 2025
@gurgunday gurgunday added the performance Issues and PRs related to the performance of Node.js. label Oct 3, 2025
@gurgunday
Copy link
Member Author

Can you update the commit message? I don't think this has anything to do with coverage, instead you can use something like lib: optimize priority queue.

Done, originally the PR only removed the check that never worked, which did increase coverage, but then I added the perf improvement

@gurgunday
Copy link
Member Author

gurgunday commented Oct 4, 2025

I need a rerun of macOS and an approval

@aduh95

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 merged commit e978a63 into nodejs:main Oct 4, 2025
52 of 53 checks passed
@aduh95
Copy link
Contributor

aduh95 commented Oct 4, 2025

Landed in e978a63

@gurgunday gurgunday deleted the pq-opt branch October 4, 2025 20:17
targos pushed a commit that referenced this pull request Oct 6, 2025
PR-URL: #60039
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. needs-ci PRs that need a full CI run. performance Issues and PRs related to the performance of Node.js.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants