Skip to content

perf: Use HashMap for OffsetSnapshot lookups #26

Description

@tomverelst

Problem

OffsetSnapshot::get_opt() in bridge-core/src/snapshot/mod.rs does linear search through the vector. For large snapshots with many consumer groups/topics/partitions, this is O(n) per lookup.

Suggestion

Use a HashMap<(ConsumerGroup, Topic, Partition), Offset> for O(1) lookups instead of iterating through the vector.

// Current: O(n) linear search
pub fn get_opt(&self, group: &str, topic: &str, partition: i32) -> Option<&OffsetRecord> {
    self.0.iter().find(|r| r.consumer_group == group && r.topic == topic && r.partition == partition)
}

// Suggested: O(1) HashMap lookup

Impact

Improves performance for migrations involving many consumer groups or topics.

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