-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
chore: tune signals for better runtime perf #9529
Conversation
🦋 Changeset detectedLatest commit: 40e2c92 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -744,12 +734,9 @@ export function get(signal) { | |||
current_dependencies_index++; | |||
} else if (current_dependencies === null) { | |||
current_dependencies = [signal]; | |||
} else if (signal.read !== current_consumer_read_clock) { | |||
} else if (signal !== current_dependencies.at(-1)) { |
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.
isn't at
like really slow compared to [.length - 1]?
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 thought it was faster?
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.
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.
Hmm, .at is faster on that site, but I got 2.5s for .at and 670ms for .length - 1, when running this snippet in my console,
{
let N = 1000000;
const arr = Array.from({length: 100}).map(Math.random);
let acc= 0;
console.log(arr.at(-1), arr[arr.length - 1])
for (var j = 1000; j--;) acc += arr.at(-1);
for (var j = 1000; j--;) acc += arr[arr.length - 1];
console.time();
for (var i = N; i--;) { acc = 0; for (var j = 1000; j--;) acc += arr.at(-1); }
console.timeEnd();
console.time();
for (var i = N; i--;) { acc = 0; for (var j = 1000; j--;) acc += arr[arr.length - 1]; }
console.timeEnd();
console.log(acc);
}
I read about it being slower somewhere because the method had to also consider ArrayLike
objects
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.
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'll put that change in the other PR.
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.
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.
Looks like the left side is slightly better.
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 think that length()
function should be faster, it will execute 0-6e instructions if nothing goes wrong like OOB, wrong object shape, etc. And at()
function will execute 0-5d, jmp to 84-8c, jmp to 6a-78. But I am not 100% sure about it, just quickly looked at it :)
We can improve some areas of the signals runtime, credit to @localvoid for pointing these out to me. :)