-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
Conversation
falsandtru
commented
Sep 3, 2022
This test often makes false positive #41839. |
Can you approve? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM while the longer version suggested by @devsnek is still nicer to read for me and I would rather keep the benchmark runs, if possible.
@@ -3,10 +3,10 @@ | |||
const common = require('../common'); | |||
|
|||
const bench = common.createBenchmark(main, { | |||
n: [1e5] | |||
n: [1e6] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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%
@@ -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); |
There was a problem hiding this comment.
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?
https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1185/ and https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1186/ don't seem to be able to reproduce the improvement. |
Since those results have no confidence, the sample size is probably insufficient. Let's set runs to 100 as my previous pr did. https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1180/ Anyway the default sample size(runs value) 30 is too small. It have to be 60 or more. |
I re-ran it with 100 iterations and now it looks the same or worse: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1188/console
https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1189/console
|
I found that CI uses Ubuntu 16 and gcc/g++8, but I'm using Ubuntu 20.04 and gcc/g++ 9.4.0. CI may be inaccurate because of its legacy environment. Can anyone run benchmark on Ubuntu 20 or later and gcc/g++ 9.4.0? |
How to
|
I ran the benchmark several times locally for 100 iterations each and on my machine (with gcc 9.4.0) I consistently get results like:
At any rate, it seems the code change here isn't a clear performance win. |
I couldn't reproduce the improvement on GitHub Actions. I've no idea what made the difference. |