otp icon indicating copy to clipboard operation
otp copied to clipboard

Add binary:join/2 to stdlib

Open onno-vos-dev opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe. Too often now have I simply copy-pasted a version of binary_join/2 to a project I'm working on. A very basic Github search (q=binary_join+language%3AErlang+&type=code) shows how widespread this copy-pasting behaviour actually is. Surely one can use: iolist_to_binary(lists:join(Separator, Binaries)) to achieve the same thing but benchmarking a correct implementation of binary:join/2 shows a significant performance difference between the two:

Measurements taken over 10_000_000 iterations

binary_join     Avg us          Total
                1.5120104159999 1512010416

lists_join      Avg us          Total
                5.5263270900000 552632709

Describe the solution you'd like Implement binary:join/2 into binary.erl so that we can once and for all stop the copy-pasting! 😄

Describe alternatives you've considered iolist_to_binary(lists:join(Separator, Binaries)) is a widespread alternative but it's much slower.

Additional context N/A

onno-vos-dev avatar Feb 08 '24 09:02 onno-vos-dev

Should this issue be closed given that https://www.erlang.org/docs/28/apps/stdlib/binary.html#join/2 exists?

ansd avatar Jun 26 '25 09:06 ansd

Should this issue be closed given that https://www.erlang.org/docs/28/apps/stdlib/binary.html#join/2 exists?

I believe so, yes. See the merged PR8100.

My only complaint is the inconsistent parameter passing compared to lists:join/2, but I assume (a) there was a reason for that, and (b) it's too late to change.

mikpe avatar Jun 28 '25 15:06 mikpe