[Feat] Slow first draws on Windows: let PathLayer `billboard` and the `project` module's projection mode compile out of the shader (≈3–4× faster D3D compile)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- typescript
- Domain
- frontend, performance
Research direction
Start by reading the shader code for PathLayer and the project module, then trace how layer props and viewport types become shader defines. Implement compile-time selection for billboard and projection modes while preserving runtime switching between the two Web Mercator modes. Done means the reported shader compile paths are reduced without changing rendering behavior; the issue offers measurements and a workaround to compare against.
Written by the indexing model from the issue text.
Description
Target Use Case
(Prepared by Claude)
Summary
On Windows, Chrome and Edge run WebGL through ANGLE on Direct3D 11, and ANGLE compiles each program's D3D vertex shader with Microsoft's fxc at the program's first draw (the HLSL depends on the draw's vertex input layout), synchronously on the GPU process's main thread. Every WebGL context in the tab shares that thread, so the whole page's WebGL stops drawing until the compile ends. With GoogleMapsOverlay (interleaved), Google's basemap freezes along with deck.
Most of that compile time is spent on code that cannot run. deck selects behaviour with runtime ifs on uniforms, and HLSL has no real function calls: everything is inlined, then optimised. PathLayer's vertex shader projects the previous, current and next point twice: once in the billboard branch and once in the other one. That makes six inlined copies of project_position, each carrying every projection mode (WEB_MERCATOR, GLOBE, WEB_MERCATOR_AUTO_OFFSET, IDENTITY) and coordinate system. A given layer in a given view only ever takes one path through it.
Making the branches that are fixed per layer or per view into compile-time defines cuts the compile ~3.5× in our measurements, with no change in behaviour.
Measurements
deck.gl 9.4.1, luma.gl 9.4.2, GoogleMapsOverlay interleaved, Windows 11, Chromium and Edge (ANGLE D3D11), NVIDIA RTX 4050 Laptop / Intel Iris Xe. Cold GPU shader cache (fresh browser profile). Browser timings come from a Chrome trace (gpu.angle category, D3DCompile events). fxc timings were taken by extracting the HLSL that ANGLE generated (it is in the trace event's source argument) and compiling it with fxc /T vs_5_0 /O1 from the Windows SDK, best of 3–5 runs.
A PathLayer (~720 paths, billboard: false, default coordinateSystem) switched on for the first time:
| Vertex shader | fxc |
D3DCompile in the browser |
|---|---|---|
| As shipped | 573–589 ms | 617–662 ms (one stall; the main thread idles, frames stop) |
path.billboard → false |
220–231 ms | 366–424 ms |
…and GLOBE / IDENTITY projection branches → false |
170 ms | 196–300 ms |
…and coordinate system fixed to LNGLAT |
156 ms | — |
The whole page load (about 40–60 D3DCompiles across all our layers, plus Google's), with the two folds applied to every layer: 1.6–2.8 s → 0.9–1.4 s of D3D compile in total; the largest single compile went from 625–1073 ms to 167–253 ms.
Chrome's on-disk GPU program cache hides this on later page loads, but every browser or driver update starts cold again, and so does every new user.
Proposal
-
billboardas a define.PathLayeralready compilesANTIALIASINGandDASH_ENABLEDas defines chosen from props. Doing the same forbillboard(#ifdef BILLBOARD … #else … #endifaround the two branches) removes half of the PathLayer vertex shader. A prop change builds another program, which luma caches by source. The sameif (x.billboard)pattern exists inScatterplotLayer,IconLayer,MultiIconLayer(text) andTextBackgroundLayer. We have not measured those, but each projects one position rather than three, so the gain is probably smaller there. -
Projection modes that a view can never use, compiled out of
project. The projection mode is a property of the viewport.WebMercatorViewportcan only produceWEB_MERCATORorWEB_MERCATOR_AUTO_OFFSET(switching at zoom 12), neverGLOBEorIDENTITY. A per-viewport-class define (e.g.PROJECTION_WEB_MERCATOR_ONLY) that removes theGLOBEandIDENTITYbranches keeps both mercator modes as runtime uniforms, so zooming across 12 still costs no recompile. The define changes only when the view type does. -
Maybe:
coordinateSystemas a define. It is a layer prop and rarely changes. In our measurements it was worth a further ~10% (170 → 156 ms). It is smaller than the other two, and a prop change would build a new program, so this one is optional.
Other candidates of the same kind that we noticed but did not measure: extruded in SolidPolygonLayer and ColumnLayer, and filled / stroked in the ScatterplotLayer fragment shader.
Workaround we are using
Text substitutions on deck's shaders before luma assembles them, applied when the props make the branch dead:
import { project } from "@deck.gl/core";
import { PathLayer } from "@deck.gl/layers";
// Every project-module consumer: a WebMercatorViewport is never GLOBE or IDENTITY.
const p = project as { vs: string };
p.vs = p.vs
.replaceAll("project.projectionMode == PROJECTION_MODE_GLOBE", "false")
.replaceAll("project.projectionMode == PROJECTION_MODE_IDENTITY", "false")
.replaceAll("project.projectionMode != PROJECTION_MODE_IDENTITY", "true");
// PathLayer, including the outlines PolygonLayer/GeoJsonLayer create.
const getShaders = PathLayer.prototype.getShaders;
PathLayer.prototype.getShaders = function () {
const shaders = getShaders.call(this);
return this.props.billboard ? shaders : { ...shaders, vs: shaders.vs.replaceAll("path.billboard", "false") };
};
ANGLE's translator drops the if (false) branch before it emits HLSL, so this gives the same result as deleting the branch (231 ms vs 247 ms in fxc). It works, but it depends on deck's GLSL text staying the same, which is why we would rather have it upstream. We are happy to open a PR for (1) and (2) if this direction is acceptable.
Related
- #1126 and #936: older reports of slow first draws caused by the size of the path and fp64 shaders.
- microsoft/angle#140: long shader compile times with ANGLE's D3D11 backend.
- Dominant language
- TypeScript
- Stars
- 14.8k
- Forks
- 2.3k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 230
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from visgl/deck.gl
-
[Bug] Tile3DLayer selects no tiles until the camera moves when tileset.json loads right after a layer updatePossibly taken @lee3Q claimed this 3 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
[Bug] SplitterWidget calls onDragStart on drag end; Deck._getViews writes into the app's views arrayPossibly taken @04jennet-coder claimed this 20 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
[Bug] WMSLayer positions EPSG:4326 images as CARTESIANPossibly taken @athomct claimed this 3 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
[Bug] MapLibreOverlay under React StrictMode: 'WebGL context already attached to device' because the attach path omits _reuseDevicesPossibly taken @jsve claimed this 84 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
visgl/deck.gl#10681 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
Similar issues
-
accessibility area:ci ci-test level:low priority:high type:test
Difficulty 2/5 1-3 hours Newbie friendliness 71/100
skytuhua-org/Gen-V1#3132 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
drmrd/vernacular#1238 ·
Maintainers usually reply within 1 day
-
question
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
enhancement migration-prioritized
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Hudson-Pufferfish/local-party-console#136 ·
Maintainers usually reply within 1 day
-
priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day