Repository navigation
Web board viewer: pan and zoom from a bitmap of the layers - #62
Open
shanedertrain wants to merge 2 commits into
Open
shanedertrain wants to merge 2 commits into
shanedertrain wants to merge 2 commits into
Conversation
plot2d.js filled and stroked every layer's Path2D on each pan or zoom frame. While the view moves, the layers now come from an offscreen bitmap with a 256 px margin, as the native window keeps a base frame: a pan inside the margin only places it, and a zoom or a longer pan stretches it until the view rests for 120 ms, when the layers are drawn again. A view that has not moved (a new plot, a fade, a layer toggled) still draws straight onto the page, and the bitmap is made when the page is idle. The corner stats show how long the layers took to draw. Headless Chrome (software raster), synthetic plot at 1600x900 (4 layers, 120 zone polygons x 2000 points, 20k tracks, 3k vias), old -> new: pan 590 -> 16.7 ms/frame, zoom 270 -> 15.7 ms/frame, first paint 65 -> 65 ms, fade 200 -> 200 ms/frame. Rested frames match apart from anti-aliasing at the viewport edge (0.6% of pixels).
A double-click fit (or a resize refit) jumps the view rather than moving it, so stretching the last bitmap until the view rests showed the zoomed-in bitmap scaled out for 120 ms. A fit now draws the layers for its view in the next frame; the frame after a double-click matches the old drawing.
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.
On a dense board, the web viewer pans at about 9 fps on a desktop GPU. Each pan or zoom frame refills and restrokes every chunk's
Path2D, including all the zone polygons. Profiling showed the cost was not in our JavaScript (about 7 ms of main-thread time per frame). It is the browser rasterizing those paths again, every frame. The phones draw on the GPU and the window keeps a base frame, so they don't have this problem.plot2d.jsnow does what the window does:drawn in N ms, how long the layers took to draw.Only
src/web/plot2d.jschanges. Nothing in Bend or on the hub is touched.Metrics
The board is a real one: our bench-rig layout, 4.4 MB
.kicad_pcb, 30 filled zones. The hub's own--plotoutput for it is 530 chunks and about 87k coordinates; it is fed toplot2d.jsexactly as the page receives it. The viewport is 1600×900 at DPR 1. The input is a scripted pan of 120 pointer moves and a zoom of 60 wheel steps, one input per frame. Each number is the median of 3 runs. Frame is the interval betweenrequestAnimationFramecallbacks; main thread is the script time inside the frame.Chrome 154 on Windows, GPU: ANGLE D3D11, RTX 4070 Ti SUPER
Chrome 154 on Linux, software raster: SwiftShader
The one-off actions are frame-quantized (16.7 ms steps). After the change they stay within one frame of before. No run had a long task (over 50 ms) during pan or zoom, before or after.
On a synthetic denser plot (software raster; 120 zone polygons of 2000 points, 20k tracks, 3k vias), pan goes from 590 to 16.7 ms per frame and zoom from 270 to 15.7 ms.
Same picture
These comparisons use the real board on the Linux software-raster renderer, and compare old and new frames at the same view.
Tests. The web bundle builds (
bend src/web/index.html). I ran the change on a second hub and then on our own hub with the board above.scripts/check.shisn't affected, since no Bend file changes. The benchmark harness is a standalone page aroundplot2d.js; I can add it undertest/tools/if you'd like it in the tree.