LHF: Pre-load locale map at server startup #14

Open
opened 2026-06-05 10:22:41 +00:00 by sebse · 0 comments
Owner

Low-Hanging Fruit

File: web/lib/apiHelpers.ts

buildItemFilter calls getServerLocaleMap() on EVERY invocation, which reads and parses two CSV files from disk (cached after first call via globalThis).

Impact

After the first request, getServerLocaleMap() returns the cached map — O(1). But the first request pays the full disk read + CSV parse cost (~200KB total). Acceptable for first request, but worth noting.

Fix

None needed — the cache works correctly after first call. Just a note for observability.

Alternative

Pre-load the locale map at server startup instead of lazily on first request:

// In a top-level module
getServerLocaleMap();

Effort

1 minute for the startup pre-load.

## Low-Hanging Fruit **File:** `web/lib/apiHelpers.ts` `buildItemFilter` calls `getServerLocaleMap()` on EVERY invocation, which reads and parses two CSV files from disk (cached after first call via `globalThis`). ### Impact After the first request, `getServerLocaleMap()` returns the cached map — O(1). But the first request pays the full disk read + CSV parse cost (~200KB total). Acceptable for first request, but worth noting. ### Fix None needed — the cache works correctly after first call. Just a note for observability. ### Alternative Pre-load the locale map at server startup instead of lazily on first request: ```ts // In a top-level module getServerLocaleMap(); ``` ### Effort 1 minute for the startup pre-load.
sebse added the low-hanging-fruit label 2026-06-05 10:22:41 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sebse/factorio-signal-exporter#14