Skip to content

slice::sort_by and slice::unstable_sort_by have bad performance when targeting wasm #27

Closed
@fitzgen

Description

@fitzgen

...but not when targeting native code.

I am very confused.

My naive Quicksort outperforms them both by a couple orders of magnitude(!!!!!) regardless which browser it is executed in (which tells me this is a Rust/LLVM issue, not wasm engine issue). This Quicksort is very naive: it is not pattern defeating, nor optimistically using insertion sort for small and mostly sorted ranges, or any of the other things that the built-in sort is doing.

https://github.com/fitzgen/source-map-mappings/blob/master/src/sort.rs

In fact, just replacing the custom swap routine with core's slice::swap causes a huge slow down. Again, only with wasm, not native code. That makes no sense to me.

  • Why is this particular performance gap occurring?

  • In the more general case, how do we debug and profile these cases where perf(wasm) != perf(native) and seemingly irrelevant changes have large effects on performance?

(I guess the first thing to do in this particular case is diff the disassembly and see how the emitted code differs? What other techniques do we have?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions