Skip to content

Performance Optimizations for Elevation Atlas #392

@SvenVw

Description

@SvenVw

Description

This issue addresses identified performance bottlenecks in the Elevation Atlas, specifically "Large HTTP Payload" and "N+1 API Calls" to PDOK services.

Identified Problems

  1. Large HTTP Payload: The /elevation route was sending full-resolution GeoJSON geometries for all farm fields, leading to slow resource loading.
  2. N+1 WMS API Calls: The WMS overview layer was making redundant requests for tiles at high zoom levels (13+), even though high-resolution COG data was already being displayed.
  3. Slow Index Retrieval: Fetching the AHN kaartblad index (~1MB) directly from PDOK on every client session was slow and prone to network latency.

Optimizations Implemented

1. Geometry Simplification (Payload Reduction)

Implemented turf.simplify in the server-side loader within fdm-app/app/routes/farm.$b_id_farm.$calendar.atlas.elevation.tsx.

  • Field geometries are now simplified with a tolerance of 0.00001 before being sent to the client.
  • This significantly reduces the vertex count and total payload size without visible loss of detail on the map.

2. Server-Side Caching for AHN Index

Created a managed server-side cache to improve reliability and speed.

  • Cache Utility: fdm-app/app/lib/ahn-cache.server.ts fetches and stores the AHN index in memory with a 24-hour TTL.
  • Resource Route: fdm-app/app/routes/resources.ahn-index.tsx serves the cached index to the frontend.
  • Frontend Integration: Updated the atlas to fetch from /resources/ahn-index, ensuring the heavy JSON is served from the local network/cache.

3. WMS Layer Constraints (N+1 Fix)

Optimized the MapLibre layer configuration to prevent redundant background requests.

  • Restricted the WMS source and layer to zoom levels below 13.
  • Added maxzoom={13} to the WMS Source.
  • This ensures that once the user zooms in enough to see high-detail COG tiles, the WMS requests (which were causing N+1 overhead) are completely stopped.

Metadata

Metadata

Assignees

Labels

branch:mainAn issue, affecting the main branch, that requires an hotfixbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions