Skip to content

v6: Use customized hashbrown raw #40

Closed

Description

@awolverp

Using Python's dictionary in Rust (instead of hashbrown) can bring algorithm speeds close to Python's own dictionary performance. Since Python's dictionary follows a FIFO algorithm, we can use the dictionary directly and just add features like memory management and maxsize.

This way, most algorithms gain significant speed improvements, and a lot of overhead is eliminated.

Of course, with this change, features like capacity control and shrink_to_fit are lost.

Also in this way library can give you more control and access to everything.

Activity

  1. self-assigned this
    on Dec 23, 2025
  2. stalkerg commented on Dec 24, 2025

    @stalkerg
    Contributor

    Since Python's dictionary follows a FIFO algorithm, we can use the dictionary directly and add features like memory management and maxsize.

    But it's still not FIFO.

    This way, most algorithms gain significant speed improvements, and a lot of overhead is eliminated.

    Can you provide examples? I just worry about GIL and how it can affect us, also, we will have more FFI calls.

  3. awolverp commented on Dec 24, 2025

    @awolverp
    OwnerAuthor

    But it's still not FIFO.

    Anyway, Python dictionaries are ordered, and this can be very helpful.

    Can you provide examples?

    For example, hasbrown only accepts usize as a hash, while Python’s hash is isize. If a dict is used, these conversions are unneeded.
    Of course, these are just theoretical, before refactoring, I’ll definitely test it to make sure.

    lrudict library is using dict inside, and now it is faster than cachebox's LRUCache

  4. stalkerg commented on Dec 24, 2025

    @stalkerg
    Contributor

    Anyway, Python dictionaries are ordered, and this can be very helpful.

    Seems like during FIFO and limit on item numbers, we should do next(iter(d)) + del (push new upfront and delete oldest item), and it's relatively expensive for PyDict.

    https://docs.python.org/3/library/stdtypes.html#dict.popitem -- popitem can remove only the first element.

  5. awolverp commented on Feb 16, 2026

    @awolverp
    OwnerAuthor

    You were right. Using dict does not make sense in some algorithms. In other hand, hashbrown removed the raw API. I should find an alternative to hashbrown that give raw access, or we should stick with old version of hashbrown.

  6. linked a pull request that will close this issuev6.0: Full Refactor #53on Jun 1, 2026
  7. changed the title [-]Use Python `dict` instead of hasbrown - Version 6.0.0[/-] [+]v6: Use customized hashbrown raw[/+] on Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions