Skip to content

Potential spoke optimisation: replace reserveId with bucketIndex and bucketMask #612

@avniculae

Description

@avniculae

At the moment all of the spoke's internal data structures are using reserveId as the mapping key(s). This adds a bit of friction when iterating over the active reserves of an user, given that we store the active reserves in the PositionStatus data structure, which uses buckets of bitmasks. While converting from reserveId to bucketIndex and bucketBit is straightforward, the vice versa is not. Hence, we have the opportunity to replace all reserveId mapping key(s) from our internal data structures with a pair of bucketIndex and bucketMask, such that we can immediately access storage when iterating through active reserves.

Conversion from reserveId to bucketIndex and bucketMask
reserveId = 130 -> bucketIndex = 1, bucketMask = (1 << (130%128)) | (1 << (130%128)+1)

Iterate over active bits of a bitmask: we extract the mask of the least significant bit (by using n - n & (n - 1)) until mask is 0

11011101010000 = n
11011101001111 = n - 1
11011101000000 = n & (n - 1)

We can also combine bucketIndex and bucketMask by hashing them together to avoid adding an additional mapping dimension.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions