[OPTIMIZATION] Utils - Algorithmic & Data Structure Issues - src/lib/utils.ts #62

Closed
opened 2026-06-06 20:46:47 +00:00 by Mark · 1 comment
Owner

Critical Issues (1)

  1. computeDashboardObservations: Nested find() inside loops - O(n²)
    • Fix: Use Map<string, Observation> for O(1) keyword lookups
    • Impact: 10-20x faster observation computation

High Issues (2)

  1. Multiple people.find(p => p.id === id) in hot paths (lines 270, 272, 277, 619, 622, 628)

    • Fix: Use existing peopleMap (already created at line 401)
    • Impact: 10-50x faster lookups
  2. Object.keys().length + spread into Set creates intermediate arrays

    • Fix: Manual iteration or use Map.size

Medium Issues (2)

  1. Dead code: getInteractionMeta never used anywhere - remove entirely
  2. Test-only functions in production bundle: exportToJson, importFromJson, parseCsv, generateId, extractKeywords, generateObservationSuggestions, getClosenessLabel
    • Fix: Move to test files or mark internal

Low Issues (1)

  1. generateId() uses Math.random() - not cryptographically secure
    • Fix: Use crypto.randomUUID()
## Critical Issues (1) 1. **computeDashboardObservations**: Nested `find()` inside loops - O(n²) - Fix: Use `Map<string, Observation>` for O(1) keyword lookups - Impact: 10-20x faster observation computation ## High Issues (2) 2. **Multiple `people.find(p => p.id === id)`** in hot paths (lines 270, 272, 277, 619, 622, 628) - Fix: Use existing `peopleMap` (already created at line 401) - Impact: 10-50x faster lookups 3. **`Object.keys().length` + spread into `Set`** creates intermediate arrays - Fix: Manual iteration or use `Map.size` ## Medium Issues (2) 4. **Dead code**: `getInteractionMeta` never used anywhere - remove entirely 5. **Test-only functions in production bundle**: `exportToJson`, `importFromJson`, `parseCsv`, `generateId`, `extractKeywords`, `generateObservationSuggestions`, `getClosenessLabel` - Fix: Move to test files or mark internal ## Low Issues (1) 6. **`generateId()` uses `Math.random()`** - not cryptographically secure - Fix: Use `crypto.randomUUID()`
Author
Owner

⏸ Needs Decision

What needs to be decided?

  • Is this issue still relevant? If yes, remove the blocked:needs-decision label to route back to triage.

Blocking factors:

  • Didn't meet auto-approve criteria — scope=small, risk=low, spec=partial

Scope: small Risk: low Spec: partial Type: enhancement
Summary: Optimize computeDashboardObservations with Map-based lookups to eliminate O(n²) patterns, remove dead code (getInteractionMeta), apply minor cleanup to utils.ts, and fix generateId() to use crypto.randomUUID().
Suggestion: Replace obsArr.find() inside forEach loops with per-person Map<string, DashboardObservation> for O(1) keyword lookups; use the already-created peopleMap where applicable; remove getInteractionMeta + its tests; move truly test-only functions (exportToJson, importFromJson, parseCsv, generateId) to test file or mark internal; change generateId to crypto.randomUUID(). Keep extractKeywords and getClosenessLabel as they are used in production code (metrics-engine.ts, PersonDetail.tsx).
Rationale: Scope is small — all changes confined to src/lib/utils.ts + test updates. Risk is low — mechanical refactoring (Map for O(1) lookup), dead code removal, and a stdlib swap (crypto.randomUUID()) with existing test coverage. The issue has minor inaccuracies (line numbers stale, mislabels extractKeywords/getClosenessLabel/generateObservationSuggestions as test-only when they're production code), but the core optimization and cleanup recommendations are sound. No AGENTS.md or milestones exist, so it's partial alignment — standard maintenance that doesn't contradict project direction.

To unblock: Remove the blocked:needs-decision label. The triage will apply the appropriate outcome based on your choice above.

## ⏸ Needs Decision **What needs to be decided?** - **Is this issue still relevant?** If yes, remove the `blocked:needs-decision` label to route back to triage. **Blocking factors:** - **Didn't meet auto-approve criteria** — scope=small, risk=low, spec=partial --- **Scope:** small **Risk:** low **Spec:** partial **Type:** enhancement **Summary:** Optimize computeDashboardObservations with Map-based lookups to eliminate O(n²) patterns, remove dead code (getInteractionMeta), apply minor cleanup to utils.ts, and fix generateId() to use crypto.randomUUID(). **Suggestion:** Replace obsArr.find() inside forEach loops with per-person Map<string, DashboardObservation> for O(1) keyword lookups; use the already-created peopleMap where applicable; remove getInteractionMeta + its tests; move truly test-only functions (exportToJson, importFromJson, parseCsv, generateId) to test file or mark internal; change generateId to crypto.randomUUID(). Keep extractKeywords and getClosenessLabel as they are used in production code (metrics-engine.ts, PersonDetail.tsx). **Rationale:** Scope is small — all changes confined to src/lib/utils.ts + test updates. Risk is low — mechanical refactoring (Map for O(1) lookup), dead code removal, and a stdlib swap (crypto.randomUUID()) with existing test coverage. The issue has minor inaccuracies (line numbers stale, mislabels extractKeywords/getClosenessLabel/generateObservationSuggestions as test-only when they're production code), but the core optimization and cleanup recommendations are sound. No AGENTS.md or milestones exist, so it's partial alignment — standard maintenance that doesn't contradict project direction. **To unblock:** Remove the `blocked:needs-decision` label. The triage will apply the appropriate outcome based on your choice above.
Mark 2026-06-29 20:36:06 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Mark/kimi_agent_kin_app_sync#62
No description provided.