Skip to content

[BUG] High time complexity of streamMoveIdmpKeys() in asmTriggerBackgroundTrim() #15001

@ShubhamTaple

Description

@ShubhamTaple

Problem

In PR #14897 streamMoveIdmpKeys() was implemented such that it takes in int slot as input parameter and iterates over server.db[0].stream_idmp_keys and moves the keys which belong to slot into stream_idmp_keys.

Therefore asmTriggerBackgroundTrim() was calling streamMoveIdmpKeys() for each slot in trim ranges.

Time Complexity

Lets say number of slots be S (it could be 16,384 in worst case)
and let K be number of keys in server.db[0].stream_idmp_keys
then the total time complexity would be O(S x K)

Suggested Fix

we have changed the implementation of streamMoveIdmpKeys() such that it now takes in slotRangeArray *slots as an input parameter and iterates over server.db[0].stream_idmp_keys once, catching all the keys which fall in the slots range and moving them to stream_idmp_keys

Therefore asmTriggerBackgroundTrim() would now call streamMoveIdmpKeys() just once.

Time Complexity

say R is number of ranges in slots and let K be number of keys in server.db[0].stream_idmp_keys
then the total time complexity would be O(R x K)

since O(R x K) is better than O(S x K) because number of slots would almost always be greater than number of ranges in slotRangeArray *slots
(for a single merged range like 0–16383, R = 1 but S = 16 384).

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