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

Use object.is for equality check #30

Closed
snnsnn opened this issue Apr 19, 2024 · 4 comments
Closed

Use object.is for equality check #30

snnsnn opened this issue Apr 19, 2024 · 4 comments

Comments

@snnsnn
Copy link

snnsnn commented Apr 19, 2024

Not a major issue but i think Object.is would be better for cheking signal updates:

export function isNotEqual(a: unknown, b: unknown) {

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness

@mihar-22
Copy link
Member

It would be but I'm not aware of the performance difference. If there's any benchmarks that we can look at that would help.

@snnsnn
Copy link
Author

snnsnn commented Apr 19, 2024

It is not about performance but reliability. Object.is returns true for Object.is(NaN, NaN) and false for Object.is(0, -0).

Since there is no implicit type conversion, it should be faster than ===.

@mihar-22
Copy link
Member

Performance is extremely important for our signals implementation, especially as the reacitvity graph becomes more deep. We have thousands of computations in our libraries that use this. Most rely on signals purely for performance. The trade off for checking something super rare like NaN, NaN and -0, +0 needs to be justified.

@snnsnn
Copy link
Author

snnsnn commented Apr 20, 2024

I could not find any definitive benchmark results that runs extensive checks. I did run some using mitata, performance difference is marginal, which favors either of them depending on the compared values and the runtime.

@snnsnn snnsnn closed this as completed Apr 20, 2024
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

No branches or pull requests

2 participants