rust-lang / rust-lang/rfcs

Ideal data block size from allocator

Open
#2,223 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

T-compiler T-libs
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

When programming dynamically allocated data structures, it's often desirable to pick the allocation block size that provides best performance and/or causes least memory overhead or fragmentation waste per unit of data. This, however, may depend on the allocator and even on the data layout. I'm proposing to add a method or methods to the Alloc trait that would return an estimation of the "best" allocation block size for the given Layout. The fuzzy value function for "best" may mean "fastest" or "most space-efficient", which two might conceivably be different. The upper bound for the resulting data block size should be the size of the OS memory page (unless a larger size is significantly more efficient with the allocator), and the default implementation could divide the page size to the array item size.

pub trait Alloc {
    // ...
    fn fastest_array_size(&self, layout: &Layout) -> usize;
    fn densest_array_size(&self, layout: &Layout) -> usize;
}

I can write up an RFC if the idea does not merit disapproval.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing issue #2223 and the proposed Alloc trait methods, including how the given Layout and allocator characteristics affect the estimate. The work is done when the proposal's performance and memory-efficiency goals are resolved into a clearly scoped RFC or the idea is rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.