Closed edwintorok closed 1 year ago
Thank you for your report. It looks like the standard ^
is much more performant than I though.
I did some benchmarks, https://github.com/Kakadu/fastware/tree/master/concat_str and I started thinking that this lint is not worth mentioning at all?.. What do you think?
I think it is still useful to avoid ^
when used in non-constant contexts, e.g. List.fold_left ( ^ )
is probably a bad idea (where the list could be thousands of elements long), using String.concat
or a Buffer would be better.
If you just have a small constant number of ^
then it probably doesn't matter much what you use.
Can the linter distinguish between the two usages?
https://kakadu.github.io/zanuda/lints/index.html#string_concat recommends
String.concat
instead of^
(good), but it also recommendsFormat.printf
. 2 problems with that:Format.sprintf
^
, it allocates more, at least according to my testHere is a very quickly written microbenchmark:
Results with OCaml 5.0 on AMD Ryzen 9 7950X:
I think this is because Printf/Format would internally use a buffer that grows (similar problem to the repeated concatenation with
^
), whereas String.concat allocates the correct size to begin by summing up the string sizes.