Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: improve priority queue performance #44506

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benchmark/util/priority-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
const common = require('../common');

const bench = common.createBenchmark(main, {
n: [1e5]
n: [1e6]
Copy link
Member

Choose a reason for hiding this comment

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

Do we have to increase the value? Our benchmarks have the tendency of taking very long overall.

Copy link
Contributor Author

@falsandtru falsandtru Sep 8, 2022

Choose a reason for hiding this comment

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

The value is needed to get *** confidence stably. And the benchmark only takes one minute even after the change.

                                 confidence improvement accuracy (*)   (**)  (***)
util/priority-queue.js n=100000                 0.46 %       ±2.98% ±3.98% ±5.20%

                                 confidence improvement accuracy (*)   (**)  (***)
util/priority-queue.js n=100000        ***      4.36 %       ±1.99% ±2.65% ±3.46%
                                  confidence improvement accuracy (*)   (**)  (***)
util/priority-queue.js n=1000000        ***      9.43 %       ±3.13% ±4.17% ±5.43%

}, { flags: ['--expose-internals'] });

function main({ n, type }) {
function main({ n }) {
const PriorityQueue = require('internal/priority_queue');
const queue = new PriorityQueue();
bench.start();
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/priority_queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
// just a single criteria.

module.exports = class PriorityQueue {
#compare = (a, b) => a - b;
#compare = (a, b) => (a > b ? 1 : a < b ? -1 : 0);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know such a common static code can commonly be compact as an idiom. How about, other members?

#heap = new Array(64);
#setPosition;
#size = 0;
Expand Down