Code review 2026-12-02 WP6: Performance #157

Closed
opened 2026-12-02 16:06:56 -05:00 by dohertj2 · 1 comment
Owner

From the 2026-12-02 full code review (commits 28b6651a, f7e4f5b4: decisions accepted 2026-12-03).

  • Findings: docs/plans/2026-12-02-full-code-review.md
  • Plan: docs/plans/2026-12-02-full-code-review-remediation.md → WP6
Task Findings Change
6.1 SRT-5 Move synchronous SQLite work off the Akka dispatcher. Decided: follow the InstanceActor pattern. The storage call runs in Task.Run, flushes chain on a persist-tail task so batches stay ordered, and reads PipeTo(Self).
6.2 SRT-7, SRT-14, CMN-11 Index expression triggers by referenced attribute. EnforceCap uses a priority structure. Look up the predictor lane in O(1).
6.3 SF-3 The sweep selects ids/lanes without payloads, then loads the payloads of the chosen page. Back it with an index.
6.4 AUD-2, AUD-3, AUD-4, AUD-7 Drop Cache=Shared. Keyset-page ReadPendingSinceAsync on an indexed (ForwardState, OccurredAt, EventId). Add an age-seekable purge index. Batch the tracking reads in the telemetry drain.
6.5 AUD-5, SEL-1 Add a (Channel, OccurredAtUtc) index and bind the channel as varchar. Add a site site_events(instance_id, timestamp) index. Migration + SQL script; site schema applied in place.
6.6 DEP-4, DEP-5, DEP-6, TPL-4 Batch the fleet staleness queries with AsNoTracking. Detach a failed staging write (like P7-5). Re-check Disabled at Send time. Use targeted single-entity loads.
6.7 MGT-5, TRN-11 Export and import resolve names with one bulk lookup per kind.
6.8 UI-6, UI-12, UI-13 Save only the overrides that changed (one transaction). Cache the auth/site lookups per poll. Decided (UI-13): split the deadline. The script deadline starts when the worker reports it is about to run user code, and a separate, generous ceiling covers start-up plus compile. A pre-warmed worker pool was rejected as more moving parts than the problem needs.
6.9 INB-2, INB-3, INB-4 Cache resolved $ref schemas per method revision. Size the audit buffer to Content-Length (capped). Expire the relay replay cache by time-ordered queue.
6.10 COMM-8, DCL-10 Run the failback probes in parallel with a bound. Use a static quality map.

Each task needs a micro-benchmark or a query plan (EXPLAIN QUERY PLAN, or sqlcmd -I with SET STATISTICS IO) before and after. Record the numbers in the commit message.

From the 2026-12-02 full code review (commits 28b6651a, f7e4f5b4: decisions accepted 2026-12-03). - Findings: `docs/plans/2026-12-02-full-code-review.md` - Plan: `docs/plans/2026-12-02-full-code-review-remediation.md` → WP6 | Task | Findings | Change | |---|---|---| | 6.1 | SRT-5 | Move synchronous SQLite work off the Akka dispatcher. **Decided:** follow the InstanceActor pattern. The storage call runs in `Task.Run`, flushes chain on a persist-tail task so batches stay ordered, and reads `PipeTo(Self)`. | | 6.2 | SRT-7, SRT-14, CMN-11 | Index expression triggers by referenced attribute. `EnforceCap` uses a priority structure. Look up the predictor lane in O(1). | | 6.3 | SF-3 | The sweep selects ids/lanes without payloads, then loads the payloads of the chosen page. Back it with an index. | | 6.4 | AUD-2, AUD-3, AUD-4, AUD-7 | Drop `Cache=Shared`. Keyset-page `ReadPendingSinceAsync` on an indexed `(ForwardState, OccurredAt, EventId)`. Add an age-seekable purge index. Batch the tracking reads in the telemetry drain. | | 6.5 | AUD-5, SEL-1 | Add a `(Channel, OccurredAtUtc)` index and bind the channel as `varchar`. Add a site `site_events(instance_id, timestamp)` index. **Migration + SQL script; site schema applied in place.** | | 6.6 | DEP-4, DEP-5, DEP-6, TPL-4 | Batch the fleet staleness queries with `AsNoTracking`. Detach a failed staging write (like P7-5). Re-check Disabled at Send time. Use targeted single-entity loads. | | 6.7 | MGT-5, TRN-11 | Export and import resolve names with one bulk lookup per kind. | | 6.8 | UI-6, UI-12, UI-13 | Save only the overrides that changed (one transaction). Cache the auth/site lookups per poll. **Decided (UI-13):** split the deadline. The script deadline starts when the worker reports it is about to run user code, and a separate, generous ceiling covers start-up plus compile. A pre-warmed worker pool was rejected as more moving parts than the problem needs. | | 6.9 | INB-2, INB-3, INB-4 | Cache resolved `$ref` schemas per method revision. Size the audit buffer to Content-Length (capped). Expire the relay replay cache by time-ordered queue. | | 6.10 | COMM-8, DCL-10 | Run the failback probes in parallel with a bound. Use a static quality map. | Each task needs a micro-benchmark or a query plan (`EXPLAIN QUERY PLAN`, or `sqlcmd -I` with SET STATISTICS IO) before and after. Record the numbers in the commit message.
dohertj2 added the type:review-findingpriority:p2 labels 2026-12-02 16:06:56 -05:00
Author
Owner

Fixed on main (pushed, 922021c4). Plan: docs/plans/2026-12-02-full-code-review-remediation.md (see its Outcome section).

All 10 tasks landed. Before/after numbers are in each commit message, for example:

  • S&F sweep over 200k rows: 1.29 s → 0.15 s.
  • Audit pull page over 1M owed rows: 2.6 s → 0.7 ms.
  • Per-channel purge: 5,858 → 6 logical reads.
  • Staleness for 1,000 instances: 5,000 → 10 queries.

Partial:

  • 6.7: TRN-11's per-row importer lookups.
  • 6.8: UI-12's Data Connections health poll.

Both are tracked in #159.

Migration: AuditLogChannelOccurredIndex. Site SQLite indexes are applied in place at boot.

Behaviour change: a shared-schema library edit now reaches running inbound methods within the method-cache TTL (5 s), not instantly.

Commits:

  • 9a574746 feat(config-db): migration AuditLogChannelOccurredIndex — partition-aligned IX_AuditLog_Channel_Occurred (AUD-5, WP6 task 6.5)
  • b3fba593 test(management): stub the analysis closure SetAlarmOverride now reads (TPL-4, WP6 task 6.6)
  • 790db4ff perf(communication,dcl): bounded-parallel failback probes; allocation-free MxGateway quality map (COMM-8, DCL-10, WP6 task 6.10)
  • 2ef2d751 perf(inbound-api): cached schema library snapshot, Content-Length-sized audit buffer, time-based replay prune (INB-2, INB-3, INB-4, WP6 task 6.9)
  • c5cd2807 perf(central-ui): save only changed overrides in one transaction; authorise once per action; split Test Run deadline (UI-6, UI-12, UI-13, WP6 task 6.8)
  • 8966c545 perf(transport,management): bundle export resolves names from projections; import memoises name and connection lookups (MGT-5, TRN-11, WP6 task 6.7)
  • 59817f50 perf(deployment,template-engine): batched untracked staleness loads, staging-failure detach, lock-held Disabled re-check, targeted single-entity loads (DEP-4, DEP-5, DEP-6, TPL-4, WP6 task 6.6)
  • 04e39690 perf(audit-log,site-event-log): channel+age purge index with varchar binding; instance+timestamp event index (AUD-5, SEL-1, WP6 task 6.5)
  • 9f03726f perf(audit-log): private-cache connections, owed-range pull index, age-seekable purge, batched tracking reads (AUD-2, AUD-3, AUD-4, AUD-7, WP6 task 6.4)
  • 54416e33 perf(store-and-forward): rank sweep lanes over a covering narrow index, join payloads for the page only (SF-3, WP6 task 6.3)
  • d3c62956 perf(site-runtime): route expression triggers by referenced keys; heap cap eviction; O(1) predictor lane (SRT-7, SRT-14, CMN-11, WP6 task 6.2)
  • 8b64d1ec fix(site-runtime): move synchronous SQLite work off the Akka dispatcher (SRT-5, WP6 task 6.1)

Deploying to QA and DEV is tracked in #160. Closing.

Fixed on `main` (pushed, `922021c4`). Plan: `docs/plans/2026-12-02-full-code-review-remediation.md` (see its Outcome section). All 10 tasks landed. Before/after numbers are in each commit message, for example: - S&F sweep over 200k rows: 1.29 s → 0.15 s. - Audit pull page over 1M owed rows: 2.6 s → 0.7 ms. - Per-channel purge: 5,858 → 6 logical reads. - Staleness for 1,000 instances: 5,000 → 10 queries. **Partial:** - **6.7:** TRN-11's per-row importer lookups. - **6.8:** UI-12's Data Connections health poll. Both are tracked in #159. **Migration:** `AuditLogChannelOccurredIndex`. Site SQLite indexes are applied in place at boot. **Behaviour change:** a shared-schema library edit now reaches running inbound methods within the method-cache TTL (5 s), not instantly. **Commits:** - 9a574746 feat(config-db): migration AuditLogChannelOccurredIndex — partition-aligned IX_AuditLog_Channel_Occurred (AUD-5, WP6 task 6.5) - b3fba593 test(management): stub the analysis closure SetAlarmOverride now reads (TPL-4, WP6 task 6.6) - 790db4ff perf(communication,dcl): bounded-parallel failback probes; allocation-free MxGateway quality map (COMM-8, DCL-10, WP6 task 6.10) - 2ef2d751 perf(inbound-api): cached schema library snapshot, Content-Length-sized audit buffer, time-based replay prune (INB-2, INB-3, INB-4, WP6 task 6.9) - c5cd2807 perf(central-ui): save only changed overrides in one transaction; authorise once per action; split Test Run deadline (UI-6, UI-12, UI-13, WP6 task 6.8) - 8966c545 perf(transport,management): bundle export resolves names from projections; import memoises name and connection lookups (MGT-5, TRN-11, WP6 task 6.7) - 59817f50 perf(deployment,template-engine): batched untracked staleness loads, staging-failure detach, lock-held Disabled re-check, targeted single-entity loads (DEP-4, DEP-5, DEP-6, TPL-4, WP6 task 6.6) - 04e39690 perf(audit-log,site-event-log): channel+age purge index with varchar binding; instance+timestamp event index (AUD-5, SEL-1, WP6 task 6.5) - 9f03726f perf(audit-log): private-cache connections, owed-range pull index, age-seekable purge, batched tracking reads (AUD-2, AUD-3, AUD-4, AUD-7, WP6 task 6.4) - 54416e33 perf(store-and-forward): rank sweep lanes over a covering narrow index, join payloads for the page only (SF-3, WP6 task 6.3) - d3c62956 perf(site-runtime): route expression triggers by referenced keys; heap cap eviction; O(1) predictor lane (SRT-7, SRT-14, CMN-11, WP6 task 6.2) - 8b64d1ec fix(site-runtime): move synchronous SQLite work off the Akka dispatcher (SRT-5, WP6 task 6.1) Deploying to QA and DEV is tracked in #160. Closing.
Sign in to join this conversation.