maciejhirsz / beef

Faster, more compact implementation of std::borrow::Cow
https://crates.io/crates/beef
Apache License 2.0
333 stars 17 forks source link

doctests fail with Rust 1.65+: std::borrow::Cow size assumption no longer valid #52

Open decathorpe opened 1 year ago

decathorpe commented 1 year ago

As of Rust 1.65.0, many enums are now smaller, probably because of this new optimization: https://github.com/rust-lang/rust/pull/94075

So as of Rust 1.65.0, std::borrow::Cow is 24 bytes in size, same as beef::Cow (at least on 64-bit architectures, I haven't checked 32-bit architectures).

Qqwy commented 1 year ago

Note: https://github.com/rust-lang/rust/issues/105371

Seems that for rustc 1.65 and 1.66 std::borrow::Cow indeed has become smaller (24 bytes), but in 1.67 it is back to 32 bytes, as result of an optimization for enums which in some cases causes regressions such as this one.

maciejhirsz commented 1 year ago

I've been a bit out of the loop for a while, and so I've missed this completely. That optimization being present renders beef pretty much obsolete, though given it's regressed there isn't much for me to do now :upside_down_face:.

I'll leave this issue open for posterity, and in case this gets changed back in std can just put a deprecation info on the crate.

Qqwy commented 1 year ago

That optimization being present renders beef pretty much obsolete

I don't think that is entirely true; at the very least the lean version will remain worthwhile even when the regression is fixed.

Also, I think that beef::lean:Cow might work vey nicely together with, for instance, rkyv, since both (by default) optimize space and performance by limiting their content length to 2^32.