Rust sort_unstable_by with more complex closure unexpectedly shrunk binary
Rust sort_unstable_by with more complex closure unexpectedly shrunk binary
Thing I stumbled upon:
I added boolean argument & if statement inside sort_unstable_by closure:
rust//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 got 1KB smaller.
I dug into & found that the reason is: quicksort fn became 980 bytes smaller.
Why? Not sure. Inlining looks same, quicksort just has fewer instructions.
target: arm-unknown-linux-gnueabihf
commit: https://github.com/tracyspacy/fli/commit/a87a98be77cc1972a53e6399716a227d1135e76b
details: https://pastebin.com/qJdTw49n
OC by @[email protected]