Files
vigilcare-records/docs/plans/performance-hardening-overview.md
Trent a17bc2b734
CI / changes (push) Successful in 17s
dotnet8-ci / build-and-test (push) Successful in 8m23s
CI / backend (push) Successful in 8m24s
node-ci / build (push) Failing after 2m1s
CI / frontend (push) Failing after 2m2s
Harden API memory and CPU usage across Phases 19–22.
Bound list/PDF payloads, stream MinIO I/O with cancellation, paginate history and FHIR $everything, tighten OCR lifetimes/buffers, and add phase tracking docs.
2026-11-30 23:55:56 +08:00

4.2 KiB
Raw Permalink Blame History

Performance Hardening Overview (Phases 19–22)

Master tracker for CPU/memory/reliability remediations identified in the VigilCareRecordsAPI static performance audit. Status values: Not started | In progress | Done.

Do not invent runtime benchmarks. Verify with code review, integration tests, and existing verification scripts. Measure with dotnet-counters / dotnet-gcdump only when validating Phase 20–21 under load.

Phase map

Audit phase Product phase Plan Focus Status
Phase 0 quick wins 19 phase-19-plan.md Bounds, tracking, over-fetch Done
Phase 1 memory safety 20 phase-20-plan.md MinIO buffering, history / $everything paging Done
Phase 2 OCR reliability 21 phase-21-plan.md OCR buffers, Azure client lifetime, cancellation Done
Phase 3 polish 22 phase-22-plan.md Fuzzy match cap, seed N+1, promote CT, ops notes Done
flowchart LR
  P19[Phase19_Bounds]
  P20[Phase20_Memory]
  P21[Phase21_OCR]
  P22[Phase22_Polish]
  P19 --> P20 --> P21 --> P22

Complete phases in order. Prefer one PR per phase; keep the phase plan checklist and this overview in sync in the same PR.

Finding → phase checklist

# Severity Finding Phase Key files Status
1 Critical MinIO download full-buffer + sync CopyTo 20 DocumentStorageService.cs Done
2 High OCR/PDF multiplies large in-memory copies 21 ImagePreprocessor.cs, TesseractOcrService.cs, AzureDocumentOcrService.cs Done
3 High Unbounded patient digitization history 20 DigitizationHistoryService.cs Done
4 High FHIR $everything loads all clinical rows 20 FhirService.cs Done
5 High Unclamped pageSize on list/queue endpoints 19 BatchService, WorkQueueService, CoverSheetService Done
6 Medium Azure OCR client scoped (handler churn) 21 Program.cs, AzureDocumentOcrService.cs Done
7 Medium Missing CT on download / OCR / promote 20–22 storage, OCR, PromotionService Done
8 Medium Unbounded cover-sheet batch PDF 19 CoverSheetController, BatchPdfRequest Done
9 Medium 1 GB container limit / OCR peak RAM 22 docker-compose.prod.yml, this overview Done
10 Medium FHIR Pretty serializer per response 19 FhirJsonOutputFormatter.cs Done
11 Medium Missing AsNoTracking / over-fetch 19 batch, cover sheet, verification, promotion reads Done
12 Medium Work-queue overview loads all pending timestamps 20 WorkQueueService.cs Done
13 Medium Upload full buffer + EnsureBucket every time 20 DocumentStorageService.cs, bootstrap Done
14 Low–Med Fuzzy match loads all same-DOB patients 22 PromotionService.cs Done
15 Low–Med Seed bootstrap MinIO N+1 22 SeedDocumentStorage.cs Done
16 Low Tesseract engine per document 21 TesseractOcrService.cs Done

Diagnostic notes (ops)

Symptom Tool
High working set / GC dotnet-counters (gc-heap-size, gen-2-gc-count, loh-size, working-set); dotnet-gcdump
Thread starvation / blocking dotnet-counters (threadpool-*); dotnet-trace
EF / large payloads Response size checks; Npgsql/EF command logging at Warning in Production
Container OOM Correlate with concurrent document downloads + OCR; see Phase 22 ops note

Memory distinctions: GC heap = managed; working set = process RSS (includes unmanaged Tesseract/ImageSharp/sockets). This hardening targets managed buffering and bounded queries first.

Non-goals

  • Premature GC / DOTNET_gcServer tuning without measured need
  • Unbounded Parallel / Channel fan-out
  • Replacing API document proxy with presigned-only delivery
  • Frontend redesign beyond consumers broken by history / $everything paging