Skip to content

'unsafe impl<A> Allocator for &A where A: Allocator' is problematic #98232

Open
@RalfJung

Description

@RalfJung

We have a general Allocator instance for &A where A: Allocator. I think that is a problem. In #98178 I fixed a problem where BTreeMap<T, Global> would actually use &Global as allocator, which leads to performance regression. Or at least, I thought I had fixed that problem -- I just realized that there are some places where it still adds an indirection and therefore adds an unnecessary reference that will be copied around:

self.range.deallocating_end(&self.alloc);

I found this by removing the unsafe impl<A> Allocator for &A where A: Allocator + ?Sized instance. I don't know of another way to avoid accidentally introducing such performance regressions.

So maybe that instance should be removed?
Cc @rust-lang/wg-allocators

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-allocatorsArea: Custom and system allocatorsC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchI-slowIssue: Problems and improvements with respect to performance of generated code.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions