java-topology/defects/thunderbird-0003/patch/thunderbird-0003_nsAutoSyncManager_IndexOf_ON2.patch

32 lines
1.3 KiB
Diff

# UNDF: UNDF-2026-000000889
--- a/mailnews/imap/src/nsAutoSyncManager.cpp
+++ b/mailnews/imap/src/nsAutoSyncManager.cpp
@@ -description
# Defect: thunderbird-0003
# Component: mailnews/imap/src/nsAutoSyncManager.cpp
# Functions: ChainFoldersInQ(), AutoUpdateFolders(), OnDownloadCompleted()
# Pattern: IndexOf() inside loops = O(N^2)
# Severity: HIGH
# Measured: 250x overhead at N=500 folders
#
# The IMAP auto-sync manager maintains priority queues of folders to sync.
# Multiple methods use IndexOf() inside loops to find folder positions:
#
# 1. ChainFoldersInQ() - nested loops O(N^2):
# for (pqidx = 1; pqidx < pqElemCount; pqidx++) {
# for (idx = 0; idx < elemCount; idx++) {
# IsSibling(aChainedQ[idx], aQueue[pqidx], isSibling);
#
# 2. AutoUpdateFolders() - IndexOf() per folder:
# for each folder:
# int32_t idx = mUpdateQ.IndexOf(autoSyncState); // O(N)
#
# 3. OnDownloadCompleted() - IndexOf() for priority reordering:
# int32_t myIndex = mPriorityQ.IndexOf(autoSyncStateObj); // O(N)
#
# This is HIGH severity because it runs on EVERY IMAP sync cycle for
# every folder. Users with 500+ IMAP folders (common in enterprise)
# experience quadratic slowdown on every sync interval.
#
# Fix: Maintain a HashMap<nsIAutoSyncState*, int32_t> for O(1) index
# lookups, updated when queue contents change.