hashbrown icon indicating copy to clipboard operation
hashbrown copied to clipboard

allocator-api2 default-feature?

Open kristof-mattei opened this issue 1 year ago • 2 comments

Hi,

I'm updating some codebase and noticed the changes wrt allocator-api2.

https://github.com/rust-lang/hashbrown/pull/417

I want to lead with the fact that I am not an advanced Rust developer, so my question may be (probably is) stupid.

From my (limited) experience, I'm not sure I understand why this feature is on by default.

I would expect a custom allocator to be opt-in, specially since it forms the foundation of all the types. It feels weird hashbrown by default uses a different allocator (albeit a c/p of the official one) than the other pieces of code that I have.

I am concerned about minor updates that could change how the allocators work as they might go out of sync.

So to alleviate that, I turned off all default features and only enabled ahash.

Next to the question above, as to why it is default, I am wondering if the turning off default features and just adding ahash is the right way to address the concern?

Thanks.

kristof-mattei avatar Nov 10 '23 23:11 kristof-mattei

I don't understand the concern. If no allocator is specified then it will always default to the global allocator (specified with #[global_allocator]. The Global allocator in allocator-api2 forwards to this.

The only reason this is an optional feature is that it needs to be disabled when hashbrown is built as part of the standard library.

Amanieu avatar Nov 15 '23 07:11 Amanieu

https://github.com/rust-lang/hashbrown/pull/417/files#diff-2e9d962a08321605940b5a657135052fbcef87b5e360662bb527c96d9a615542R41

My concern is that allocator-api2 is pulled in by default if we don't disable it.

kristof-mattei avatar Nov 17 '23 15:11 kristof-mattei