Skip to content

Workflow status is tracked in GitHub: https://github.com/emulebb/emulebb/issues/124. This local document is retained as an engineering spec/evidence record.

REF-053 - Reduce upload queue and upload list linear lookup overhead

Summary

Several upload queue and upload list paths still rely on linear scans for membership and lookup checks. With current fixed upload slot caps this is not a major runtime issue, but the pattern is repeated in UI refresh, stale-row guards, upload-client lookup, and per-file statistics.

If broadband defaults or operator slot caps grow, these paths can become avoidable UI and timer overhead.

Representative Sites

  • srchybrid/UploadListCtrl.cpp checks whether a row client is still uploading by scanning the upload list.
  • srchybrid/UploadListCtrl.cpp visible refresh calls that liveness check per visible row.
  • srchybrid/UploadQueue.cpp GetUploadingClientStructByClient() scans active upload entries and already carries a TODO for a faster lookup.
  • srchybrid/UploadQueue.cpp file-specific waiting and datarate helpers scan waiting/uploading lists and compare hashes for each requested file.

Candidate Fix Direction

  • Maintain an upload-client membership/index map alongside uploadinglist.
  • Optionally maintain a requested-file hash index for waiting clients if profiling shows file-specific scans are meaningful.
  • Keep the existing list as the ordering source of truth unless a broader container refactor is approved.
  • Update maps only at the same ownership points that add, remove, retire, or reclaim upload entries.
  • Add targeted tests around map/list consistency and stale-client pruning.

Scope Constraints

  • Do not change upload scheduling policy or score semantics.
  • Do not change upload-list ordering or visible sort behavior.
  • Do not make helper-thread readers mutate upload queue containers.
  • Do not replace the list container wholesale unless profiling justifies a broader refactor.

Acceptance Criteria

  • [ ] Active upload client membership checks do not scan the entire upload list in per-row UI refresh paths.
  • [ ] GetUploadingClientStructByClient() has O(1) or otherwise bounded lookup behavior for active clients.
  • [ ] Map/list consistency is preserved across add, remove, retire, stale prune, reclaim, and shutdown paths.
  • [ ] Existing upload scheduling and slot ordering behavior is unchanged.
  • [ ] Performance counters or focused tests demonstrate the intended lookup reduction.

Validation

  • focused native tests for active upload lookup consistency
  • focused native tests for stale upload entry retirement and reclaim behavior
  • manual Uploading list refresh smoke with multiple active slots
  • x64 Debug and Release app builds before implementation commit