fix(atoms): fix and optimize quicksort calculations #209
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
#203 introduced a bug in the quicksort algorithm (totally my bad - the equivalent of
2 ** iteration
before isdivisor * 2
, notdivisor * 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
anddeepPropagation
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.