Skip to content

Conversation

@trueadm
Copy link
Contributor

@trueadm trueadm commented Nov 18, 2023

We can improve some areas of the signals runtime, credit to @localvoid for pointing these out to me. :)

@changeset-bot
Copy link

changeset-bot bot commented Nov 18, 2023

🦋 Changeset detected

Latest commit: 40e2c92

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

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

@vercel
Copy link

vercel bot commented Nov 18, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
svelte-5-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 18, 2023 11:02am

@trueadm trueadm merged commit bbd1a6c into main Nov 18, 2023
@trueadm trueadm deleted the tune-signals branch November 18, 2023 11:36
} else if (current_dependencies === null) {
current_dependencies = [signal];
} else if (signal.read !== current_consumer_read_clock) {
} else if (signal !== current_dependencies.at(-1)) {
Copy link
Contributor

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]?

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 thought it was faster?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

ESBench results with the same code from measurethat
image

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'll put that change in the other PR.

Choose a reason for hiding this comment

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

image

On the left side is at() function, and on the right side is length() function.

function at(i) {
  return i.at(-1);
}
function length(i) {
  return i[i.length - 1]
}

Copy link
Contributor Author

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.

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 :)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants