Skip to content
This repository has been archived by the owner on Aug 3, 2022. It is now read-only.

Use Pointers to store CuckooSet #16

Merged
merged 5 commits into from Jun 18, 2022
Merged

Conversation

crichez
Copy link
Owner

@crichez crichez commented Jun 12, 2022

Objectives

This pull request improves the per-insert performance of CuckooSet by changing its backing storage from Array to UnsafeMutablePointer.

Implementation

When initializing a set, every pointer in the buffer is initialized to nil to indicate an empty bucket. This operation still takes linear time as the initializer must iterate through every pointer in the buffer. The buffer's header is empty. Instead of storing capacity and count in the header, they are stored inline at the class definition. This may change to simplify copy-on-write semantics, but for now should provide meager performance benefits.

Performance

Benchmark output on the CuckooSet<Int> Insert task outputs the following comparison statistics:

Tasks with difference scores larger than 1.05:
  Score   Sum     Improvements Regressions  Name
  1.341   1.341   1.341(#76)   1.000(#0)    CuckooSet<Int> Insert (*)

The CuckooSet<Int> Contains task showed no significant improvement.

Most of this improvement is associated with the removed bounds checks associated with unsafe pointers. This significantly reduces memory safety, but our tests guarantee this implementation is safe.

@crichez crichez added the enhancement New feature or request label Jun 12, 2022
@crichez crichez self-assigned this Jun 12, 2022
@crichez crichez marked this pull request as draft June 12, 2022 20:37
@crichez
Copy link
Owner Author

crichez commented Jun 12, 2022

I am dealing with the same issue locally and remotely where tests pass individually but fail when ran as a batch. This does suggest some memory safety issues. I need to look into ManagedBuffer more. I believe I am meant to subclass with a deinit override to deallocate everything before the program exits.

@crichez crichez changed the title Use ManagedBuffer to store CuckooSet Use Pointers to store CuckooSet Jun 18, 2022
@crichez
Copy link
Owner Author

crichez commented Jun 18, 2022

Last commit uses a CuckooStorage class that references capacity, count and the base pointer to the elements. These deinitialized and deallocated when the storage instance is deallocated.

@crichez crichez marked this pull request as ready for review June 18, 2022 14:56
@crichez crichez merged commit edea288 into master Jun 18, 2022
@crichez crichez deleted the set-insert-optimization-1 branch June 18, 2022 14:57
@crichez crichez added the needs minor version bump Fixing this issue or releasing these changes requires a minor version bump label Jun 21, 2022
@crichez crichez added this to the v0.1.0 milestone Jun 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request needs minor version bump Fixing this issue or releasing these changes requires a minor version bump
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant