svix-webhooks
svix-webhooks copied to clipboard
format!() should not be used inside loops
format!()
macro should be avoided in places where it is called repeatedly, e.g. inside loops like this https://github.com/svix/svix-webhooks/blob/main/server/svix-server/src/core/types.rs#L429. Even if that line is not inside a loop it will be called repeatedly on every property it serializes.
An alternative can be picked from this list https://github.com/hoodie/concatenation_benchmarks-rs and also check this discussion on Reddit https://www.reddit.com/r/rust/comments/t06hk7/string_concatenations_benchmarks_updated/.
Additional info: https://github.com/hoodie/concatenation_benchmarks-rs/pull/11 (not merged yet at the time of reporting, but contains useful info on crates implementing fast concatenation).
Some of the macros benchmarked in that study have very good performance, but I would check their source and what they expand to before picking the winner. They all serve a slightly different purpose.
Oh nice, thanks for the report, and you're most definitely right!