Map: draw the ground off the keystroke, and stop reprojecting the world
A pan cost 0.9-2.4 s. It was never the tiles - those already load in a thread - it was render_map, which rasterizes the vector ground on the paint path: 900-2342 ms for a view holding ~16k features. Two changes, in that order. The projection was doing the same trigonometry once per vertex. Every feature_to_dot call recomputed Viewport.origin_world - a sin/log pair - and a 2** for values constant across the whole frame, 107k times a frame. The mapping is affine in tile-local coordinates, so tile_transform folds it into three numbers and _draw_tile spells the arithmetic out inline: two multiplies and two adds per vertex, no call at all. That alone is 2.4x (z12 2342 -> 991 ms). The rest is genuinely per-feature Python and will not shrink to keystroke size, so the raster moved off the paint path. A paint now returns the best picture available immediately and a background task draws the real one: unchanged view serves the finished frame; a view that only gained a tile keeps the old raster, which is still correctly aligned; a view that *moved* draws the nodes alone on the new viewport, which is a few ms, so panning tracks the keys and the streets catch up. The title says "drawing..." while it does. Exactly one raster runs at a time and it is always the newest requested - a held arrow hands us a new viewport every repaint, and starting a second of thread-bound work per keypress would queue frames that are already stale on arrival and slow the keystrokes this exists to protect. On the device: pan 1205 -> 89 ms, 1156 -> 130 ms, 2449 -> 91 ms; zoom 1161 -> 142 ms; a settled view 37 ms. Also flips MESHTERM_FASTRENDER on by default (=0 still opts out), and asks whether a loop is running *before* building a coroutine, so a static render no longer leaves an un-awaited one behind. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
57386fe879
commit
e53e35523e
6 files changed
+270
-17
No files matched your search
@@ -235,10 +235,19 @@ def _draw_tile(frame: _Frame, layers: list[Layer], z: int, x: int, y: int) -> No
|
||||
vp = frame.canvas
|
||||
by_name = {layer.name: layer for layer in layers}
|
||||
|
||||
# The tile-local -> dot projection is affine, and every layer in a tile shares the
|
||||
# same extent in practice, so its three coefficients are resolved once per extent and
|
||||
# the per-vertex work is spelled out inline below (see Viewport.tile_transform): a
|
||||
# downtown frame projects ~50k vertices, and at that count even the function call per
|
||||
# vertex is worth removing.
|
||||
transforms: dict[int, tuple[float, float, float]] = {}
|
||||
|
||||
def project(ring: list[tuple[int, int]], extent: int) -> list[tuple[float, float]]:
|
||||
return [
|
||||
frame.viewport.feature_to_dot(x, y, z, extent, lx, ly) for lx, ly in ring
|
||||
]
|
||||
t = transforms.get(extent)
|
||||
if t is None:
|
||||
t = transforms[extent] = frame.viewport.tile_transform(x, y, z, extent)
|
||||
bx, by, step = t
|
||||
return [(bx + lx * step, by + ly * step) for lx, ly in ring]
|
||||
|
||||
# Fills first (water, green space) so lines and labels sit on top.
|
||||
for name in _FILL_LAYERS:
|
||||
|
||||
Reference in new issue
Block a user