Skip to content

BUG: O(n²) bubble sort in fetcher batch ordering #1080

Description

@andrinoff

Describe the bug

fetcher/fetcher.go:505-511 sorts each batch by UID using nested loops:

for i := 0; i < len(batchEmails); i++ {
    for j := i + 1; j < len(batchEmails); j++ {
        if batchEmails[j].UID > batchEmails[i].UID {
            batchEmails[i], batchEmails[j] = batchEmails[j], batchEmails[i]
        }
    }
}

Quadratic on every batch. The default chunk size is 50 so it's not catastrophic, but with a larger limit it becomes the dominant cost of the fetch.

Expected behavior

Replace with sort.Slice(batchEmails, func(i, j int) bool { return batchEmails[i].UID > batchEmails[j].UID }).

Activity

  1. mavonx commented on Apr 27, 2026

    @mavonx
    Member

    /assign

  2. moved this from Backlog to In review in v1 Releaseon Apr 27, 2026
  3. moved this from In review to Done in v1 Releaseon Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions