Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: recognize and use over sized allocations #523

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Commits on May 8, 2024

  1. perf: increase min buckets on very small types

    Consider `HashSet<u8>` on x86_64 with SSE with various bucket sizes and
    how many bytes the allocation ends up being:
    
    | buckets | capacity | allocated bytes |
    | ------- | -------- | --------------- |
    |       4 |        3 |              36 |
    |       8 |        7 |              40 |
    |      16 |       14 |              48 |
    |      32 |       28 |              80 |
    
    In general, doubling the number of buckets should roughly double the
    number of bytes used. However, for small bucket sizes for these small
    TableLayouts (4 -> 8, 8 -> 16), it doesn't happen. This is an edge case
    which happens because of padding of the control bytes and adding the
    Group::WIDTH. Taking the buckets from 4 to 16 (4x) only takes the
    allocated bytes from 36 to 48 (~1.3x).
    
    This platform isn't the only one with edges. Here's aarch64 on an M1
    for the same `HashSet<u8>`:
    
    | buckets | capacity | allocated bytes |
    | ------- | -------- | --------------- |
    |       4 |        3 |              20 |
    |       8 |        7 |              24 |
    |      16 |       14 |              40 |
    
    Notice 4 -> 8 buckets leading to only 4 more bytes (20 -> 24) instead
    of roughly doubling.
    
    Generalized, `buckets * table_layout.size` needs to be at least as big
    as `table_layout.ctrl_align`. For the cases I listed above, we'd get
    these new minimum bucket sizes:
    
     - x86_64 with SSE: 16
     - aarch64: 8
    
    This is a niche optimization. However, it also removes possible
    undefined behavior edge case in resize operations. In addition, it
    may be a useful property to utilize over-sized allocations (see
    rust-lang#523).
    morrisonlevi committed May 8, 2024
    Configuration menu
    Copy the full SHA
    f637220 View commit details
    Browse the repository at this point in the history
  2. feat: recognize and use over sized allocations

    Allocators are allowed to return a larger memory chunk than was asked
    for. If the amount extra is large enough, then the hash map can use the
    extra space. The Global allocator will not hit this path, because it
    won't over-size enough to matter, but custom allocators may. An example
    of an allocator which allocates full system pages is included in the
    test suite (Unix only because it uses `mmap`).
    morrisonlevi committed May 8, 2024
    Configuration menu
    Copy the full SHA
    89f6d1f View commit details
    Browse the repository at this point in the history

Commits on May 18, 2024

  1. fix test accuracy

    morrisonlevi committed May 18, 2024
    Configuration menu
    Copy the full SHA
    15fcd44 View commit details
    Browse the repository at this point in the history