Skip to content

perf(ogc): faster page parsing and chunk combination - #345

Closed
thodson-usgs wants to merge 3 commits into
DOI-USGS:mainfrom
thodson-usgs:perf/chunk-client-side
Closed

perf(ogc): faster page parsing and chunk combination#345
thodson-usgs wants to merge 3 commits into
DOI-USGS:mainfrom
thodson-usgs:perf/chunk-client-side

Conversation

@thodson-usgs

Copy link
Copy Markdown
Collaborator

Summary

Two client-side performance improvements to the OGC page-parsing and chunk-combination paths, identified through profiling the parallel_chunks fan-out code.

Changes

  1. Replace pd.json_normalize with pd.DataFrame in _get_resp_data (shaping.py)

    OGC API feature properties are flat dictionaries — json_normalize's recursive nesting support is unnecessary overhead. Direct pd.DataFrame construction is 2.4× faster per page (3.2 ms → 1.35 ms on 2500-feature pages).

  2. Skip drop_duplicates when the plan has no filter axis (planning.py, chunking.py)

    List-axis chunks (the common parallel_chunks case — splitting on monitoring_location_id, parameter_code, etc.) produce non-overlapping partitions by construction. Only filter-axis chunks (splitting on CQL OR clauses) can overlap. _combine_chunk_frames now accepts a dedup flag and ChunkedCall._combine_raw passes dedup=self.plan.has_filter_axis2.7× faster combine (3.4 ms → 1.25 ms on 52k-row results) for the common case.

Impact

For a typical 32-chunk query fetching 32 pages (~52k rows):

  • Page parse savings: ~1.85 ms × 32 pages = ~59 ms saved
  • Combine savings: ~2.2 ms saved
  • Total: ~61 ms less client-side overhead per query

These are additive to the network-latency savings parallel_chunks already provides.

Testing

All 574 tests pass. No behavioral change — list-axis chunks were never producing duplicates (the dedup was a no-op); filter-axis chunks still dedup as before.

Add parallel_chunks(n) so large Water Data and NGWMN queries can split
into more independently paginated sub-requests while preserving the
conservative byte-limit-only default.

Cap optional fan-out across all chunk axes, validate positive integer
inputs, export the helper publicly, and document usage, tradeoffs, and
benchmark results. Add planner, context, and integration coverage.
- Replace pd.json_normalize with pd.DataFrame in _get_resp_data.
  OGC API properties are flat dicts; json_normalize's recursive
  flattening is unnecessary overhead (~2.4× faster per page:
  3.2 ms → 1.35 ms on 2500-feature pages).

- Skip drop_duplicates in _combine_chunk_frames when the plan has
  no filter axis. List-axis chunks produce non-overlapping
  partitions, so dedup is pure overhead in the common
  parallel_chunks case (~2.7× faster combine: 3.4 ms → 1.25 ms
  on 52k-row results).

- Add ChunkPlan.has_filter_axis property to distinguish plans that
  need dedup (filter-axis overlap possible) from those that don't
  (list-axis only).
@thodson-usgs

Copy link
Copy Markdown
Collaborator Author

Closing as stale.

The branch is CONFLICTING, and it still carries feat(ogc): add opt-in parallel chunk fan-out — which landed separately as #341 — so the PR duplicates already-merged history. The ogc/ package has since been split up in #346 and #348, and is being restructured again in #350/#351, so the files this patches no longer look like this.

The two perf findings are real and are not on main yet. Worth redoing against current main:

  1. pd.json_normalizepd.DataFrame in _get_resp_data (now dataretrieval/ogc/shaping.py:126). OGC feature properties are flat dicts, so the recursive-nesting path is pure overhead — measured 2.4× faster per page (3.2 ms → 1.35 ms on 2500-feature pages).
  2. Skip drop_duplicates when the plan has no filter axis (now dataretrieval/ogc/combining.py:144). List-axis chunks partition by construction, so the dedup pass can't find anything.

Branch perf/chunk-client-side is retained if we want to cherry-pick the perf commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant