Skip to content

perf(services): apply barrel-surgery to the ~20-service tail (follow-up to #4571) #4649

Description

@koala73

Follow-up to #4571 / PR #4640, which shed the 5 weight-bearing side-effectful services (economic/market/aviation/trade/consumer-prices) from eager main.js via barrel surgery. The mechanism is proven and guarded; this issue applies it to the remaining tail.

The tail

src/services/index.ts still export *'s ~20 more services that run a module-load side effect (new XServiceClient() / createCircuitBreaker() at top level). By side-effect count: supply-chain (4), conflict (5), infrastructure (5), research (4), climate (4), prediction (2), maritime (2), unrest (2), and ~12 more with 2 each. Individually small (diminishing returns vs the heavy 5), but each still forces its client init into eager parse.

Recipe (proven in #4640)

Per service, measure-gated:

  1. Remove export * from './<svc>' from src/services/index.ts.
  2. Repoint its consumers — panels import @/services/<svc> directly (already lazy); dynamic-import any data-loader.ts fetchers inside their viewport-gated method(s). For a big method with multiple try blocks, put the import at method scope and guard it (try/early-return + console.warn) if any caller is unguarded.
  3. Add the service name to the DEFERRED list in tests/services-barrel-eager-guard.test.mts (already guards both export * AND named re-exports).
  4. Measure-gate: VITE_VARIANT=full vite build --sourcemap → byte-attribute the service = 0 in main.js.

#3242 note

The circuit-breaker registry (src/utils/circuit-breaker.ts:468) degrades gracefully on a missing breaker, so lazy registration is safe as long as no eager path reads that service's breaker by name before first load. Grep getCircuitBreakerCooldownInfo/isCircuitBreakerOnCooldown per service before deferring (economic's 'FRED Batch' was the only such lookup in the heavy 5).

Low priority — the boot-parse win per tail service is small (~1-2KB min each). Batch a few per PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:frontendFrontend components, layout, visual encodingclaudeGenerated with Claude CodeperformancePerformance optimization

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions