Skip to content

Conversation

@muendlein
Copy link
Contributor

@muendlein muendlein commented Dec 3, 2025

Fixes #69

I have now switched to a non recursive implementation in order to solve this once and for all. There is a minor performance penalty for the indexing part (215ms -> 255ms) which I still think is worth it. Even with an optimized recursive implementation there can be datasets that fail or that require random numbers in the algorithm which would also slow it down.
@mourner What do you think?

@muendlein muendlein changed the title Use 3way partitioning quicksort Switch to non recursive quicksort Dec 5, 2025
@mourner
Copy link
Owner

mourner commented Dec 5, 2025

215 to 255 is a 19% increase, which is quite significant — I'd love to see if we can fix this without a big regression for all cases. In theory, the non-recursive version shouldn't be slower — I'll see if there are any microoptimizations available here...

@muendlein
Copy link
Contributor Author

I guess microoptimizations are possible however it being slower very much depends on the JS engine as well the hardware. A function call stack is handled differently from a custom stack. Anyhow there are also other options to get faster, i.e. by using insertion sort once the partition is small enough.
Apart from that how do you want me to get rid of current typing errors that show up due to pop() indicate possible undefined?

@mourner
Copy link
Owner

mourner commented Dec 6, 2025

@muendlein for type checking, we can add ignores similar to the existing ones in places where it's hard to type soundly: https://github.com/mourner/flatbush/blob/main/index.js#L304

@muendlein
Copy link
Contributor Author

muendlein commented Dec 7, 2025

@mourner I have added some performance improvements which now brings the performance to the same speed.

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.

[BUG] Duplicate elements triggering max recursion depth error during sort.

2 participants