Skip to content

Vector Rendering First-Frame Performance Plan 2/3 - #96

Merged
pmeems merged 8 commits into
developmentfrom
phase-2-fast-triangulation-background
Nov 26, 2026
Merged

pmeems merged 8 commits into
developmentfrom
phase-2-fast-triangulation-background

Conversation

@pmeems

@pmeems pmeems commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Phase 2 replaces first-use GEOS triangulation with earcut and prepares missing
fill meshes in the background, so Automatic rendering can present a GDI frame
without blocking on mesh generation.

The renderer uses at most four polygon workers, keeps GEOS as the fallback, and
publishes results only on the control thread after validating layer ID, scene
identity, and generation token. Pending work is discarded after replacement or
invalidation.

The ISC-licensed earcut-hpp dependency is added through vcpkg. Project memory
now records the dependency wiring and background cache lifecycle.

Validation: Debug x64 MSBuild completed with 0 warnings; all 493 non-interactive
CTest cases passed. The Release real-dataset lazy-fill benchmark completed 2,470
polygons in 93.8 ms.

- use earcut with bounded parallel triangulation and a GEOS fallback
- publish immutable scene results on the control thread and discard stale work
- cover pending, ready, failed, replaced, and cancelled mesh states

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 23:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved defects can terminate the process during worker startup, overwrite unrelated cached layers, reject valid triangulations, and prevent mesh publication after control reactivation.

4 open issues
What changed in this PR

This PR implements Phase 2 of the first-frame performance plan: faster polygon triangulation in Core and background fill-mesh preparation in ActiveX, allowing Automatic rendering to use GDI while meshes are pending.

Changes:

  • Adds earcut as the triangulation fast path, retaining GEOS as fallback.
  • Introduces bounded background workers, owner-thread publication, and cancellation of stale mesh work.
  • Updates regression tests, performance documentation, and project memory.

Project builds and test suites were not run during this review.

File Description
vcpkg.json Adds the earcut dependency.
tests/​MapWinGIS.Core.Tests/​PolygonTriangulationTests.cpp Adds touching-hole coverage and adjusts failure fixtures.
tests/​MapWinGIS.Core.Tests/​PerformanceDiagnosticsTests.cpp Updates expectations for triangulation without validity prechecks.
tests/​MapWinGIS.ActiveX.Tests/​VectorLayerRendererTests.cpp Tests background states, cancellation, replacement, and fallback.
tests/​MapWinGIS.ActiveX.Tests/​RenderingBaselineTests.cpp Allows either backend for the first presented frame.
tests/​MapWinGIS.ActiveX.Tests/​OpenGlVectorLayerRendererTestAccess.h Exposes background preparation controls to tests.
src/​MapWinGIS.Core/​src/​rendering/​PolygonTriangulation.cpp Implements earcut triangulation with area checks and GEOS fallback.
src/​MapWinGIS.Core/​include/​mapwingis/​rendering/​PolygonTriangulation.h Documents the revised triangulation contract.
src/​MapWinGIS.Core/​CMakeLists.txt Links earcut privately into Core.
src/​MapWinGIS.ActiveX/​VectorLayerRenderer.h Exposes preparation and publication operations.
src/​MapWinGIS.ActiveX/​VectorLayerRenderer.cpp Queues background meshes during Automatic fill drawing.
src/​MapWinGIS.ActiveX/​OpenGlVectorLayerRenderer.h Declares worker lifecycle and preparation states.
src/​MapWinGIS.ActiveX/​OpenGlVectorLayerRenderer.cpp Implements parallel preparation, publication, and cancellation.
src/​MapWinGIS.ActiveX/​MapWinGISControl.h Declares completion dispatch ownership and callbacks.
src/​MapWinGIS.ActiveX/​MapWinGISControl.cpp Integrates preparation with loading, redraws, and teardown.
README.md Describes background preparation and mesh reuse.
docs/​TESTING.md Updates test expectations and records benchmark results.
docs/​ARCHITECTURE.md Documents worker, publication, and cache lifecycles.
.github/​plans/​Vector-Rendering-First-Frame-Performance.md Records Phase 2 completion and remaining limitations.
.ai/​memory/​build/​dependencies.md Records earcut dependency wiring.
.ai/​memory/​architecture/​activex.md Records background preparation and cancellation behavior.

Review effort: Balanced

@Victor-MW-cl Victor-MW-cl left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review completed against the repository's reviewing-pull-requests skill and the development base. I inspected the changed implementation, tests, dependency wiring, documentation, and current review threads. I found no additional distinct findings to post; the four existing unresolved inline findings already cover the issues identified in this pass. CI was still in progress at the time of review. No approval or change-request decision has been submitted.

@pmeems pmeems changed the title MapWinGIS6 – Vector Rendering First-Frame Performance Plan Vector Rendering First-Frame Performance Plan Nov 25, 2026
@pmeems pmeems changed the title Vector Rendering First-Frame Performance Plan Vector Rendering First-Frame Performance Plan 2/3 Nov 25, 2026

@Julian-MW Julian-MW left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Automated review against the repository's review skill and the development base. Final decision is with the human reviewer. The four existing unresolved inline findings (worker-startup std::terminate, reactivation of preparation/dispatch, cache erase-iterator overwrite, shoelace area cancellation in projected coordinates) still apply and were not duplicated here.

CI — needs attention before merge:

  • Major | High: build-debug-x64 (legacy MSBuild leg) fails at this head SHA (198cdae): the build and parity steps succeed, but the Test step fails after ~24 s. Every other leg — including Release MSBuild (build-release-x64) and the CMake VS Debug x64 leg, which run the same test suites — passes, and development is green, so this is very likely caused by this PR. The PR body states all 493 non-interactive tests pass; the failing Debug x64 MSBuild test run contradicts that and should be investigated (I could not access the job log to identify the failing test).
  • Minor (infrastructure): cmake-vs-release-x64 / build is stuck: its Configure CMake step has been "in progress" for 8+ hours despite the 180-minute job timeout. This looks like a hung runner rather than a code problem — cancel and re-run it so the merge gate can clear.

@pmeems
pmeems enabled auto-merge (squash) November 26, 2026 00:00
- make worker teardown and cancellation exception-safe
- restart preparation after control reactivation
- stabilize earcut mesh validation and renderer regression tests

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 00:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved renderer recovery and job-handling defects can leave layers stuck on GDI or meshes permanently pending, while triangulation tolerances can accept incorrect polygon fills.

2 open issues
3 previously missed issues

In code that hasn't changed since last review

Medium severity Completion allocation failure strands cache entries pending

src/​MapWinGIS.ActiveX/​OpenGlVectorLayerRenderer.cpp:955

Severity: Minor | Confidence: High

If completed.push_back fails to allocate, this handler drops the result after its active token and cancellation flag have already been erased. The owner-thread cache remains Pending, but there is no remaining job or completion to transition it, and future preparation calls skip the same scene. Preserve a failure outcome that can be delivered without another allocation, or provide an owner-thread recovery path that resets the matching Pending entry.

Medium severity Failed completion posts are never retried while idle

src/​MapWinGIS.ActiveX/​OpenGlVectorLayerRenderer.cpp:962

Severity: Minor | Confidence: High

If posting the last or only completion fails, the result remains queued but no retry is scheduled: the worker waits for another job, and retrying only on later completions cannot help an idle control. Once the GDI layer bitmap is cached, subsequent paints bypass VectorLayerRenderer::Draw, so they do not publish the result either. Schedule an independent retry wake or owner-thread timer while unpublished results remain, and cover a single completion whose first post fails.

Medium severity Area tolerance accepts incorrect self-intersecting meshes

src/​MapWinGIS.Core/​src/​rendering/​PolygonTriangulation.cpp:391

Severity: Major | Confidence: High

For the self-intersecting ring (0,0), (2e-6,2e-6), (2e-6,0), (0,1e-6), this tolerance accepts earcut's mesh area of 2e-12 against an expected 1e-12, allowing an incorrect fill. The clipping behavior was checked in v3.2.4 and matches the linked default-branch code. Use a scale-aware error bound for both triangulation paths, including the GEOS return at line 434, and add a scaled self-intersection regression.

4 resolved since last review

Review effort: Balanced

- continue background preparation while OpenGL retries initialization
- commit pending state only after cancellation and queue bookkeeping succeeds

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 00:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Unresolved findings can strand pending meshes, leave completed meshes unpublished, block the control thread with duplicate preparation, and allow incorrect polygon fills to bypass fallback.

No open issues 🎉

4 previously missed issues

In code that hasn't changed since last review

Medium severity Completion allocation failure can leave cache entries permanently pending

src/​MapWinGIS.ActiveX/​OpenGlVectorLayerRenderer.cpp:970

Severity: Minor | Confidence: High

If completed.push_back throws, the job's active token and cancellation flag have already been erased, and the only result is dropped. The cache entry remains Pending with no work to resolve it, so subsequent preparation skips the layer permanently even after memory pressure subsides. Allocate durable completion storage before enqueueing the job, or retain an allocation-free failure signal that lets the owner thread leave Pending.

Medium severity Failed completion wake is never retried

src/​MapWinGIS.ActiveX/​OpenGlVectorLayerRenderer.cpp:977

Severity: Minor | Confidence: High

If the last outstanding completion's wake fails, the worker waits for new jobs and never retries it. Cached GDI paints bypass publication, leaving ready meshes unpublished even after the message queue recovers. Retry while completions remain, for example with the existing dispatch-window retry timer, and stop retries when results are drained or the control closes.

Medium severity OpenGL paint synchronously regenerates meshes already being prepared

src/​MapWinGIS.ActiveX/​OpenGlVectorLayerRenderer.cpp:1834

Severity: Major | Confidence: High

An explicit-OpenGL control paint during background preparation cancels a matching Pending entry and regenerates its meshes synchronously. This blocks the control thread and can compute in-flight polygons twice, since both load paths already queue background work. Preserve entries backed by background work and use GDI until publication; keep synchronous lazy preparation for entries without background work.

Medium severity Absolute area tolerance accepts invalid exterior-only meshes

src/​MapWinGIS.Core/​src/​rendering/​PolygonTriangulation.cpp:391

Severity: Major | Confidence: High

The 1.0 floor accepts an exterior-only mesh of area 1.6e-11 for a [0,4e-6]² square with an outside [10e-6,11e-6]² ring, whose expected area is 1.5e-11. Earcut's upstream default branch skips unbridgeable rings, so this tolerance lets an incorrect OpenGL fill bypass fallback. Remove the absolute floor and add a scaled invalid-ring regression.

2 resolved since last review

Review effort: Balanced

- reserve completion storage before accepting jobs
- retry failed completion wakes through the dispatch window timer
- preserve pending background work during explicit OpenGL draws
- reject invalid tiny-scale polygon fills before fallback

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 01:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved completion-handling defects can terminate the host on allocation failure or leave rendering results unpublished when the cross-thread retry timer fails.

3 open issues

Review effort: Balanced

- retain reserved completion capacity across owner-thread publication
- retry failed worker wake posts without cross-thread timers
- use batched GEOS coverage checks for interior rings

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 06:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

A failed wake-post retry loop can survive cancellation and block jobs after reactivation, and constructor allocation failures can leak the GEOS context.

2 open issues
3 resolved since last review

Review effort: Balanced

- stop failed completion wakes when a layer is cancelled or replaced
- retain the GEOS context in RAII during validation setup

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 07:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed to evaluate triangulation that can violate even-odd fill behavior and a holed-polygon path that bypasses required GDAL initialization.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

- initialize GDAL before holed-ring GEOS validation
- validate full hole polygons and reject overlapping interiors

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 07:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Hole validation performs quadratic GEOS relation checks against all earlier holes, creating a severe single-polygon performance bottleneck for valid polygons with many interior rings.

1 open issue

Review effort: Balanced

- query only envelope-overlapping holes before exact GEOS relation checks

- cover polygons with many disjoint interior rings

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 10:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed to evaluate subtle fill-parity risks for retraced polygons and stale screen caches caused by mesh-completion ordering.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@pmeems
pmeems merged commit ecb85a2 into development Nov 26, 2026
34 of 35 checks passed
@pmeems
pmeems deleted the phase-2-fast-triangulation-background branch November 26, 2026 12:02
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.

4 participants