koala73 / koala73/worldmonitor
perf(services): apply barrel-surgery to the ~20-service tail (follow-up to #4571)
- Dominant language
- TypeScript
- Stars
- 86.6k
- Forks
- 13.1k
- Avg merge
- 8h 4m
- Merged PRs (30d)
- 825
Description
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 './'` from `src/services/index.ts`.
2. Repoint its consumers — panels import `@/services/` 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.
Contributor guide
Research direction
Start with src/services/index.ts and tests/services-barrel-eager-guard.test.mts, then inventory the remaining tail services and their consumers. Check each service for eager circuit-breaker lookups using the named functions, and run VITE_VARIANT=full vite build --sourcemap. Done means selected services no longer use barrel exports, guarded consumers remain lazy, each is in DEFERRED, and its bytes are absent from main.js.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vite
- Domain
- build-system, performance
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100