navi/backend/services
malice 7c10b80d08
navi-offroute: numpy-pack TrailheadIndex (memory opt #2) (#32)
Apply the proven OSMParkingIndex (PR #31) memory-pack pattern to TrailheadIndex,
which the 2026-05-26 memory audit flagged at ~300-450 MB/worker using the old
list[dict]+list[Point] storage.

- mvum_transitions.py: store coords as packed float64 numpy arrays (_lats/_lons)
  and attributes as interned lists (_names/_road_classes); build candidate record
  dicts lazily via _record(i) in query_trailheads_near_line instead of holding
  740k dicts + 740k shapely Point objects. Points are built only to construct the
  STRtree, then released. Adds a records property (lazy, for tests/introspection)
  and tracks build_time_seconds + memory_estimate_mb (psutil RSS delta) like
  OSMParkingIndex. Query logic (coarse STRtree bbox + precise degree-distance
  check) unchanged.
- admin.py: GET /api/admin/trailhead/info -> {count, build_time_seconds,
  memory_estimate_mb}, mirroring /api/admin/osm-parking/info.

Tests: existing test updated (len(records)==count; the removed _points assertion)
plus a numpy-backing test (_lats/_lons dtype float64, len==count). Full offroute
suite: 83 passed.

Real-DB sanity (not deployed): index loads 740,430 entry points in ~4.8 s using
~285 MB RSS (down from the audit's inferred ~300-450 MB; same ~40% pack ratio as
parking), query returns 317 trailheads on a Redfish Lake corridor.

Co-authored-by: Matt <mj@k7zvx.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 16:46:22 -06:00
..
navi_admin fix: include navi-offroute (8428) in navi-admin fleet list 2026-05-23 23:17:23 -06:00
navi_config Add navi-admin service (extraction #7) (#7) 2026-05-22 21:21:00 -06:00
navi_contacts Add navi-admin service (extraction #7) (#7) 2026-05-22 21:21:00 -06:00
navi_geo shared: promote dem.py to shared/ (prep for navi-offroute) (#9) 2026-05-22 22:42:47 -06:00
navi_landclass Add navi-admin service (extraction #7) (#7) 2026-05-22 21:21:00 -06:00
navi_offroute navi-offroute: numpy-pack TrailheadIndex (memory opt #2) (#32) 2026-05-26 16:46:22 -06:00
navi_places navi-places: name-based wikivoyage article discovery (#30) 2026-05-26 09:55:48 -06:00
navi_traffic Add navi-admin service (extraction #7) (#7) 2026-05-22 21:21:00 -06:00