Skip to content

.clear() taking too long #162

Open
Open

Description

@abhimanyu891998

Hey @manugoyal , when calling .clear() on cuckoohash_map, it takes about 1-2 ms. Is this expected? And is there a faster way to reset the hash map?

Activity

  1. manugoyal commented on Jun 15, 2024

    @manugoyal
    Contributor

    Hi @abhimanyu891998. Off the top of my head, I would guess clear takes a while because it must take all the table locks (

    auto all_locks_manager = lock_all(normal_mode());
    ). This is necessary because clearing cannot race with other concurrent operations on the table which may be reading/writing data.

    It would be useful to benchmark what part of clear is taking a long time for you. If you are running clear at a point where no concurrent operations are running on the table, I would think that acquiring all the uncontended locks should be pretty fast, and clear shouldn't take much time. In which case, there might be other reasons.

    If you are trying to clear while concurrent operations are occurring, the fastest approach might be to replace the table with a freshly-allocated one. Which could be safely managed with shared pointers or something. For example:

    auto my_table = std::make_shared<cuckoohash_map<int, int>>(...);
    // Do stuff
    ...
    // Quickly "clear" the table by replacing it with a fresh one. Existing concurrent operations will continue
    // to operate on the old table.
    my_table = std::make_shared<cuckoohash_map<int, int>>(...);
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions