Skip to content

perf: avoid repeated projection in CustomProjectionView layers - #11126

Open
athomct wants to merge 5 commits into
visgl:masterfrom
chesapeake-tech:codex/custom-projection-preprojection-cost
Open

athomct wants to merge 5 commits into
visgl:masterfrom
chesapeake-tech:codex/custom-projection-preprojection-cost

Conversation

@athomct

@athomct athomct commented Nov 15, 2026 •

Copy link
Copy Markdown

Closes #11125
For #10739

Background

BitmapLayer.updateState compares bounds by reference. A TileLayer renderSubLayers callback returns a new bounds array on each render, so each sublayer update builds the mesh again. In a _CustomProjectionView, a refined mesh projects many vertices.

SolidPolygonLayer triangulates with viewport.projectPosition(position, {sourceCrs: packedCrs}). CustomProjectionViewport converts these packed positions to WGS84 and back before it scales them.

Change List

  • BitmapLayer: compare bounds by value before the mesh rebuild
  • CustomProjectionViewport.projectPosition: scale positions packed in the view CRS
  • Unit tests: converter call counts, mesh reuse, other source CRS

The sourceCrs check is an identity check against viewport.crs, the descriptor that getPreprojection returns as packedCrs. A descriptor of another CRS, or of the same CRS from another projection engine (#11112), still converts through WGS84. The change adds no cache.

Before / After

A basemap of vector and raster tiles in a _CustomProjectionView (UTM zone 32N), headed Chromium. The script makes 30 wheel steps out and 30 in, two times. Medians of 3 runs per variant, with alternating runs. The machine had a high load (load average 37 to 50), so compare the variants, not the absolute values.

Before After
Main-thread busy time 109.7 s 26.8 s
Long tasks 91 (106.2 s) 73 (23.0 s)
Frame interval p95 24.9 ms 16.7 ms
Forward conversions 157.8 million 22.3 million
Inverse conversions 1.8 million 0.18 million
Bitmap mesh rebuilds on update 438 0

Unit tests: SolidPolygonLayer does one forward conversion per vertex (before: two forward and one inverse). BitmapLayer keeps its mesh when bounds are equal by value.

Questions

This PR touches the same bounds condition as #11030. The imageMapping branch in #11031 compares bounds by reference too. Should that branch also compare by value?


Note

Low Risk
Low risk performance optimizations that avoid redundant bounds-driven mesh recomputations and CRS conversions without altering external projection APIs.

Overview
Optimizes rendering performance by eliminating redundant mesh rebuilds and coordinate conversions in custom projection workflows.

In BitmapLayer, bounds are now compared by value via deepEqual rather than reference to avoid recreating costly meshes when callers supply new array instances with identical values. In addition, the vertex count is now preserved on recreated models when extensions change.

In CustomProjectionViewport.projectPosition, coordinates already expressed in the viewport's CRS (sourceCrs === this.crs) now bypass the intermediate round-trip through WGS84 and are scaled directly to common space.

Reviewed by Cursor Bugbot for commit 3f6743b. Bugbot is set up for automated code reviews on this repo. Configure here.

BitmapLayer now compares bounds by value before it builds a new mesh.
Tile layers give each sublayer a new bounds array on each update. In a
CustomProjectionView, each new mesh projects many vertices again.

CustomProjectionViewport.projectPosition now only scales positions that
are already packed in its own CRS. Before, polygon triangulation
converted each packed vertex to WGS84 and back.

Add tests for the converter call counts and for mesh reuse.
@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues were found.

Summary

Removes repeated coordinate conversions and bitmap mesh rebuilds.

  • Custom-projection views scale positions already packed in their CRS.
  • Bitmap layers keep their mesh when bounds values stay the same.

Reviews (3) · Last reviewed commit: "Merge master into codex/custom-projectio..." · Reviewed by Greptile

When extensions change, BitmapLayer makes a new model. With bounds that
are equal by value, the mesh is kept, so the rebuild branch that sets
the vertex count does not run, and the new model draws nothing.
Set the count from the kept mesh when the model is replaced.
Keep both new BitmapLayer tests at the end of bitmap-layer.spec.ts.
@coveralls

coveralls commented Nov 16, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 82.765% (+0.01%) from 82.755% — chesapeake-tech:codex/custom-projection-preprojection-cost into visgl:master

@greptile-apps greptile-apps Bot 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@greptile-apps greptile-apps Bot 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Layers in _CustomProjectionView project the same vertices again

4 participants