tokio-rs / bytes

Utilities for working with bytes
MIT License
1.86k stars 278 forks source link

Should clone benchmark use use `test::blackbox`? #690

Closed wyfo closed 4 months ago

wyfo commented 5 months ago

I've recently run the bytes.rs benchmarks, and was quite surprised that clone_shared was identical to clone_arc_vec. That should not be the case with the indirection caused by the vtable. Actually, the compiler seems to be smart enough to inline the vtable, hence this result (I haven't checked on godbolt because the library feature is broken).

However, if we replace &bytes.clone() by test::black_box(test::black_box(&bytes).clone()), a (small) difference appears, and I think it should be more representative of arbitrary code in which bytes can be used. Is it a good idea to update the benchmarks?

Darksonn commented 5 months ago

That sounds like a reasonable suggestion.