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

fix(atoms): fix and optimize quicksort calculations #209

Merged
merged 2 commits into from
Mar 13, 2025

Conversation

bowheart
Copy link
Collaborator

Description

#203 introduced a bug in the quicksort algorithm (totally my bad - the equivalent of 2 ** iteration before is divisor * 2, not divisor * divisor 🤦 ). This fortunately made me realize we don't have tests for that algorithm. So fix the problem and add tests.

While I was in there, I played with tweaking the maths slightly and actually procured a 10-15% speed boost. The broadPropagation benchmark (the one that utilizes the scheduler the most) is down from ~760 ms to ~690 ms. avoidablePropagation and deepPropagation are almost 20% faster.

All of this has led me to realize that the O(n) push-pull algorithm being O(2n) is actually a big deal here. We'd typically say 2n and n are the same big O, but when you're comparing to O(n log n), they're not. 2n is always worse than n log n. The only reason Zedux's scheduling isn't faster than push-pull-based signals libs is because we can't control array resizing. Our splice call alone is 80% of the total job scheduling time. And job scheduling is 25% of total execution time in the benchmarks.

Regardless, despite being 10% slower at broad propagation, Zedux is now about 10% faster than SolidJS at running the full benchmark suite (27.6s vs 31s). I am still planning on switching to a push-pull model.

@bowheart bowheart merged commit a262e65 into master Mar 13, 2025
2 checks passed
@bowheart bowheart deleted the josh/quicksort-fixes branch March 13, 2025 01:49
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.

1 participant