effekt-lang / effekt

A language with lexical effect handlers and lightweight effect polymorphism
https://effekt-lang.org
MIT License
335 stars 24 forks source link

Make 'list::sort' quick by using natural mergesort #711

Open jiribenes opened 1 week ago

jiribenes commented 1 week ago

Please see issue #710 for context and analysis. (Resolves #710)

It would be nice if somebody benchmarked this properly: the old quicksort, this new quicksort on JS and LLVM + with JS native sort, but I can notice the improvement as this version can suddenly quickly sort huge random lists.

Other considerations:

jiribenes commented 1 week ago

It seems that this change makes Valgrind very unhappy with the LLVM backend :)

https://github.com/effekt-lang/effekt/actions/runs/11990743350/job/33428584571#step:11:164

Screenshot 2024-11-23 at 23 07 43
jiribenes commented 6 days ago

I tried improving both the performance and the stack safety here by making certain parts (mergeAll) more imperative, but it didn't really work (actually made it measurably slower!)

jiribenes commented 15 hours ago

In a "real" application (and by that I mean AoC), this change saves 25-50% of the run time:

Before
✓ 1: JS [6.44ms]
✓ 2: JS [103.46ms]
✓ 1: LLVM [0.27ms]
✓ 2: LLVM [17.80ms]

After
✓ 1: JS [5.66ms]
✓ 2: JS [80.25ms]
✓ 1: LLVM [0.12ms]
✓ 2: LLVM [8.72ms]