Rust sort_unstable_by with more complex closure unexpectedly shrunk binary

5 points by tracyspacy 11 hours ago

Thing I stumbled upon:

I added boolean argument and if statement inside sort_unstable_by closure:

``` //from

|&a, &b| compare(a, b)

//to

|&a, &b| if is_reverse { compare(b, a) } else { compare(a, b) } ```

I expected binary to grow slightly, but actually it became ca 1KB smaller.

I dug into with bloaty and found that the reason is: quicksort fn became 980 bytes smaller.

Still not sure why. Inlining looks same, quicksort just has fewer instructions.

target: arm-unknown-linux-gnueabihf

details: https:// pastebin.com/qJdTw49n

commit: https://github.com/tracyspacy/fli/commit/a87a98be77cc1972a53e6399716a227d1135e76b

Comments (2)