Skip to content

⚡️ perf(rendering): cache render scenes per map layer - #79

Merged
pmeems merged 5 commits into
developmentfrom
phase-7-per-layer-render-scenes
Nov 15, 2026
Merged

pmeems merged 5 commits into
developmentfrom
phase-7-per-layer-render-scenes

Conversation

@pmeems

@pmeems pmeems commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implements phase 7 of .github/plans/development-review-fix-plan-20261113.md.

  • Cache prepared render scenes by LayerId. Visibility changes retain geometry, hidden layers prepare when first shown, and removal or clearing releases the corresponding cache entries.
  • Add MapView::InvalidateLayerScene() for selective refresh or retry. InvalidateScene() clears every layer cache.
  • Ignore attributes during geometry traversal. Compute slow extents in that pass and cache them for later map fits.
  • Store polygon coordinates and ring/polygon offset ranges in PolygonBuffer. Triangulation, GDI, and OpenGL read borrowed views without reconstructing nested vectors. The user approved this scope during local review.
  • Preserve existing snapshot storage when adding another prepared scene. Keep allocation failures recoverable, including failures from driver capability probes.
  • Add regressions for caching, ordering, selective retry, allocation failure, attribute restoration, slow extents, and flat-buffer ownership and bounds.
  • Update README, architecture, testing, native compatibility documentation, the plan, and shared architecture memory.

Local review

Reviewed every changed file in .worktrees\pr-79. The branch already contained the latest development commit (77f7404), so merging the base required no new commit and produced no conflicts.

Fixed the original tests' unique_ptr/shared_ptr conversion errors and unused-variable warnings. Also fixed unnecessary snapshot reconstruction on prepared-layer insertion, an extra slow extent scan during loading, and termination on an allocation failure in the extent-capability probe. There were no existing review comments or unresolved threads when work began.

Local validation

Windows, Visual Studio 18 Community, MSVC 14.52, x64:

  • CMake x64-debug: build passed and CTest ran 413 cases with zero failures.
  • CMake x64-release: build passed and CTest ran 413 cases with zero failures.
  • Each standard CTest run skipped the network case and two opt-in rendering baselines.
  • MSBuild Debug | x64: solution build passed without warnings. Core passed 335 cases with one network case skipped, GDAL initialization passed all three cases, and ActiveX passed 71 non-interactive cases with two performance cases skipped.
  • Release rendering: both opt-in baselines ran with 100,000 generated features, and all 35 renderer regression/pixel cases passed. The original 34 cases also passed before the flat-buffer change. A new case compares every pixel before and after copying a scene and releasing its original coordinate buffers.
  • Source builds introduced no warnings. Existing CMake ActiveX-test compilation emits D9025 for conflicting /external:W0 and /external:W4 command-line options.

Builds reused existing vcpkg dependencies without changing shared install trees. Local Release used the default driver set, not CI's full-drivers feature set. Interactive COM registration/hosting and network tests were not run. Build configuration files did not change, so compile-command parity was not rerun.

Before/after measurements

Sequential Release runs compare development at 77f7404 with this implementation. Each run generated a GeoPackage containing 100,000 32-vertex polygons and a 256-byte string attribute. A map displayed two copies of that source layer. Visibility timings are medians of three operations and include Scene() assembly, but not drawing.

Operation Before After
Prepare one source scene 4,857.6 ms 4,986.7 ms
Add a second already-prepared layer 0.0033 ms 42.2 ms
Hide one layer and assemble the map 5,083.0 ms 68.7 ms
Show that layer and assemble the map 10,004.8 ms 95.1 ms
Additional process-private memory after an already-prepared first scene, with both map layers present 169.4 MiB 466.1 MiB

Visibility changes avoid repeated reads and triangulation. Initial preparation did not improve in this run because triangulation still dominates. Prepared insertion now copies the new layer into its cache.

Compatibility and memory cost

VectorRenderScene::polygons changes from nested vectors to PolygonBuffer. This changes the native structure layout: native clients must rebuild against the matching headers and Core DLL. Standalone Polygon, Ring, and their triangulation overload remain available. No COM interface, IID, CLSID, DISPID, or type-library version changes.

MapRenderScene remains an owning snapshot. Each layer cache owns another copy of coordinates and meshes, so the faster visibility path costs additional memory. Flat buffers reduce per-ring allocation overhead but do not remove snapshot copying.

Failed layer diagnostics stay cached until invalidation. Duplicate map layers have independent caches even when they share one source. Invalidate each affected LayerId, or invalidate the whole map after source edits.

@pmeems
pmeems marked this pull request as ready for review November 14, 2026 13:58
@pmeems
pmeems added this pull request to stack #83 November 14, 2026 14:00
@pmeems
pmeems force-pushed the phase-7-per-layer-render-scenes branch from 4499834 to 176e343 Compare November 14, 2026 19:44
- Reuse cached layer geometry across visibility changes
- Add selective layer-scene invalidation
- Skip attribute reads and compute slow extents during geometry traversal
- Cover cache reuse and update rendering documentation
@pmeems
pmeems force-pushed the phase-7-per-layer-render-scenes branch from 176e343 to 53d78ad Compare November 15, 2026 12:59
Retain prepared snapshot storage, cache slow extents, and propagate driver capability allocation failures. Add owned flat polygon buffers, renderer adapters, regression coverage, and local validation results.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@pmeems pmeems left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review of the original PR head 53d78ad. Final decision is with the human reviewer.

All five findings below are fixed in f792c5a. The historical line comments document the defects and their fixes, not outstanding work. There were no existing comments to duplicate.

Recommendation: approve once CI passes. Risk: Medium because the user-approved flat-buffer redesign changes the native scene layout and caching increases memory use. Native clients must rebuild; COM contracts are unchanged.

Local Debug and Release CMake builds each ran 413 non-interactive cases with zero failures and three opt-in skips. MSBuild Debug built without warnings and its Core, GDAL initialization, and non-interactive ActiveX suites passed. Both Release rendering benchmarks ran at 100,000 features. All 35 renderer regression cases passed, including full-pixel equality after copying a flat scene and freeing its original buffers. The original 34 renderer cases also passed before changing storage.

The PR description contains sequential before/after timings and memory costs. Visibility hide/show assembly fell from approximately 5.08/10.00 seconds to 68.7/95.1 milliseconds. Initial preparation did not improve, and extra private memory rose from 169.4 to 466.1 MiB in the two-layer benchmark. Win32 and full-driver Release remain for CI; interactive registration and network checks were not run locally.

Finding counts: Critical 0, Major 2, Minor 3, Suggestion 0. Duplicates skipped: 0. Outstanding findings after the fixes: 0.

Comment thread src/MapWinGIS.Core/src/map/MapView.cpp Resolved
Resolve the shared plan checklist conflict while retaining both phase result sections. The merged Debug x64 build passed and CTest ran 419 cases with zero failures and three optional skips.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pmeems
pmeems enabled stacked auto-merge (squash) November 15, 2026 15:22
stacked auto-merge was automatically disabled November 15, 2026 15:47

Replaced by a newer auto-merge request

@pmeems
pmeems enabled stacked auto-merge (squash) November 15, 2026 15:47
@pmeems
pmeems merged commit 006adc2 into development Nov 15, 2026
6 checks passed
@pmeems
pmeems deleted the phase-7-per-layer-render-scenes branch November 15, 2026 18:01
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