Repository navigation
Draw geometry-file circle tiles with WebGL2 - #46
Merged
Merged
Conversation
The tile worker drew a nationwide circle set on the 2D canvas, reading every block of the geometry file twice through an 8-block cache and building an object, a Path2D and a colour string per circle: about 2.4 s a tile on a Pixel 5a. Each block is now read once and its records are read as numbers; a dot that a later circle replaces in the same pixel is blanked in place, which keeps the draw order. The circles are drawn as WebGL2 instances (fill and outline from the distance to the centre, as on iOS and Android) on one OffscreenCanvas the tiles take turns at. A tile with a circle bent into its 128-gon, polygon and polyline tiles, and workers without WebGL2 keep the 2D canvas. useGl = false in the worker's console draws everything on the 2D canvas.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The tile service worker draws a nationwide circle set (the geometry file, used past 2,000 circles) with WebGL2 instead of the 2D canvas. This is the web counterpart of MapConductor/ios-sdk-core#41 and MapConductor/android-sdk-core#44.
What was slow
On a Pixel 5a, a zoomed-out tile of US Antenna Horizons (723,800 circles) took about 2.4 s. The service worker is single-threaded, so nine tiles took 13.6 s. Measured inside the worker, the time split about evenly into two parts:
Both read every block of the geometry file (about 425 KB each from Cache Storage) through a cache of 8 blocks, which a nationwide tile overflows, so each block was read twice. They also built an object, a
Path2Dand a colour string per circle. The PNG encoding (20–40 ms) and the index query were small.What changed (
renderCircleFileTileGl)OffscreenCanvasfor the worker. Tiles take turns at it between their block reads, andconvertToBlobmakes the PNG.The 2D canvas still draws:
Running
useGl = falsein the worker's console draws everything on the 2D canvas, to compare.Measurements
Pixel 5a, Brave (Chromium 157), US Antenna Horizons on MapLibre. The first nine tiles (2x), time until each finished:
Desktop Chromium. Sixteen tiles at z9, z11 and z13 over New York, Chicago, Los Angeles and Houston, plus four z4 tiles: 776 ms on WebGL2 against 1,268 ms on 2D.
What is left is mostly reading the blocks from Cache Storage. Keeping a compact copy of the circles in the worker's memory (about 20 MB for 723,800 circles) would remove that, but the file exists to save that memory, so it is a separate decision.
Checks
npm test: all 426 pass. Node has no WebGL2, so the tests take the 2D path as before.useGlon and off and compared pixel by pixel: