Skip to content

Faster lookup if utilizing perfect hashing? #9

@simendsjo

Description

@simendsjo

First off, thanks a lot for Sycamore! It is the key library for my little vaporware game. But because of this, I'm also having performance issues even though I see it is highly optimized; nearly all CPU and allocations happens in sycamore.

I have some thoughts on how to make things faster, but I'm not sure how feasible it is to do within sycamore or if I can use parts of sycamore to achieve my goals.

I have primarily two kinds of hash-maps, one where I have fixnum as key and use :test #'cl:= :hash-function #'identity. It stores data using the strictly increasing id's for game objects. This is the kind of map I think might benefit the most from a special implementation, but I'm not sure given that sbcl is quite good at optimizations and there are quite some type hints in your library. As it's a perfect hash function, it wouldn't need any collision detection or bucket implementation at all.

The other use is where I use keywords as keys and :test #'eq :hash-function #'sb-kernel:symbol-hash. I would have loved to just used the :test #'cl:= :hash-function sb-kernel:get-lisp-obj-address and thus reuse a perfect hash implementation, but I guess the keywords can move around in memory unless I take some special care.

I also noticed it reused the hash-set implementation by doing (cons key value) which also turned up as one of the main sources of list allocations. Not sure if avoiding this would yield much benefit, but at least it showed up as a big source of allocations.

Do you think an optimized "perfect hash" implementation is useful in sycamore, or is it way to specialized? Will creating a hardcoded version for fixnum and perfect hashing yield any benefits you think? Could parts of sycamore be reused for such an implementation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions