GeezerVison is showing github.com — Merge pull request #35 from i2cjak/backplane/fix-perf-lag · BackplaneWorks/Backplane@07cadd4
File treeExpand file treeCollapse file tree Open diff view settings android/app/src/main/java/dev/backplane/mobile
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: AGENTS.md +6-2Lines changed: 6 additions & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -18,10 +18,10 @@ When using Bend: | 18 | 18 | - `PROOF.bend`: a proof of every law. `bend PROOF.bend` must print "All terms check." | 19 | 19 | - `src/core/`: pure Bend. JSON, S-expressions, the event-sourced thread model, the settle rule, sidebar order, KiCad parsing, scene diff and fade, semver, and the prompt/skills logic. No IO here. | 20 | 20 | - `src/server/`: the Bend program that owns IO: HTTP/WebSocket, the event store, agent processes, git, file watching, and updates. Custom effects (`*.c` + `*.js` twins) are in `src/server/effects/`. | 21 | | -- `src/app/`: the native app (the default `backplane`). A Bend window client in the same process as the hub: `nui.bend` (input → state, pure), `layout.bend` (state → draw ops + hit regions), `main.bend` (event loop), `effects/win.c` (X11 window, dlopen'd libX11). | | 21 | +- `src/app/`: the native app (the default `backplane`). A Bend window client in the same process as the hub: `nui.bend` (input → state, pure), `layout.bend` (state → draw ops + hit regions), `main.bend` (event loop), `effects/win.c` (X11 window, dlopen'd libX11; `Win.show` gets the last frame too, skips regions that are the same node in both, and sends X only the 64 px blocks whose pixels changed). | 22 | 22 | - `src/gfx/`: the rasterizer. Draw ops become Base's `Image` quadtree in parallel (`raster.bend`); `draw.bend` builds ops; `font.bend` is generated from Spleen 8x16. `text.bend` is system-font text (fontconfig + FreeType via `effects/font.c`, dlopen'd): faces, a glyph cache in Bend state, measure/wrap/draw; `patches/raster-bitmap-shape.patch` adds the `SMask` coverage shape it draws with. | 23 | 23 | - `src/gfx/mesh.bend`: the 3D viewer's rasterizer and camera. The camera turns freely about the model's centre like SolidWorks (controls in `nui.bend`, `Drag.mode`/`Key3.act`, laws `view_drag_*`, `view_key_*`); edges are watertight (measured from their first end, so no cracks); a view at rest takes four samples a pixel (a drag draws a half-size draft). Tests: `test/cam_test.bend`; `test/native/pcb3d_frame.bend` writes both kinds of frame. | 24 | | -- `src/gfx/tiles.bend`: frames kept as 64 px tiles, each drawn in its own coordinates; the next frame redraws only tiles whose ops or base changed, and a tile the thread scrolled takes the image the last frame drew where it came from (`Past`, `Tiles.seek`; the shift hint is nui.bend's `Hits.slide`, and a wheel notch is one tile, `Nui.notch`) (laws `tiles_again_exact`, `frame_again_exact`, `tile_keep`, `seek_made`). The timeline keeps each entry's laid-out lines the same way (`TL.memo` in `layout.bend`, laws `tl_*`). Both compare with `src/core/eq.bend`/`Eq.*`, exact equalities whose soundness is proven, so nothing stale is reused. | | 24 | +- `src/gfx/tiles.bend`: frames kept as 64 px tiles, each drawn in its own coordinates; a node whose ops and base are unchanged is kept whole, and the next frame redraws only tiles whose ops or base changed, drawn in parallel from a plan (`Frame.par`: `Tiles.plan`, `Jobs.deal`, `Plan.fill`; laws `frame_par_exact`, `plan_fill_again`, `drawn_get_run`), and a tile the thread scrolled takes the image the last frame drew where it came from (`Past`, `Tiles.seek`; the shift hint is nui.bend's `Hits.slide`, and a wheel notch is one tile, `Nui.notch`) (laws `tiles_again_exact`, `frame_again_exact`, `tile_keep`, `seek_made`). The timeline keeps each entry's laid-out lines the same way (`TL.memo` in `layout.bend`, laws `tl_*`). Both compare with `src/core/eq.bend`/`Eq.*`, exact equalities whose soundness is proven, so nothing stale is reused. | 25 | 25 | - `src/gfx/bitmap.bend`: raw RGB frames (the browser helper's frame file) as an `Image` quadtree, composited into a frame at a place and size. | 26 | 26 | - `src/core/svg.bend` (pure: SVG path data parsed, written, flattened; laws `svg_*`) and `src/core/icons.bend` (the icon set, Lucide paths, ISC; laws `icons_*`). The window rasterizes them once into `SMask` bitmaps in the glyph cache (`src/gfx/icon.bend`, `Lay.icon`/`Lay.ibutton`); the web writes them as inline `<svg>` (`src/web/icon.bend`). Test: `test/svg_test.bend`. | 27 | 27 | - `tools/browser/`: `backplane-browser`, a Bun + playwright-core headless Chromium driven by NDJSON on stdin/stdout; raw frames go to a file. Pages are keyed by an owner (`"page"`: a bot's id for a bot's thread, else the thread's id, `BT.World.page`, so every thread drives its own; `""` is the shared page, which Backplane no longer uses), all in one persistent profile (`<home>/browser-profile`); each page's JPEG frames go to `<home>/shots/<owner>.jpg`. Bend side: `src/server/browser.bend` (`Browser.ask_on`, test `test/browser_test.bend`). Protocol in its README; `bun tools/browser/test/pages.ts` tests it. Built by `scripts/build-browser.sh`. | @@ -115,6 +115,10 @@ Headless UI checks: start Xvfb on `:77`, run `DISPLAY=:77 BACKPLANE_SNAP=/tmp/sn | 115 | 115 | - `.` and `_` mangle alike in C: `TL.mine.of` and `TL.mine_of` both become `..._TL_MINE_OF`, and the native build stops with "two names mangle to". `--check-only` does not catch it. | 116 | 116 | - Launch time: nothing slow may run before the window opens (probes, network, full log copies). Start it after, in the background, and serve the last answer meanwhile (`src/core/boot.bend`). `test/native/boot_bench.bend` times start-up and frames on a real log. | 117 | 117 | - CPU forks are dealt out once, not stolen: fork over one flat balanced tree of work items (all primitives of all nodes) rather than nesting forks per group; nested forks inside a heavy group barely spread. | | 118 | +- The runtime deals out a value's work at the first fork it meets while evaluating it, and everything after runs where it was dealt. A spatial quadtree whose busy part sits in one corner (a thread's text) ran on one core however many there were. Collect the heavy items into a list, deal them round robin into a balanced tree (`Jobs.deal` in tiles.bend), and evaluate that tree in its own `do` binding so its forks are the first ones (main.bend's `Shell.present`). `test/native/par_bench.bend` shows each shape on 1 and 16 cores. | | 119 | +- Fork arguments are fine to be cheap references: the runtime's rc counts make a shared list read by many lanes cost atomics, but the balanced tree above still spread 10x. | | 120 | +- In the JS build (web, phones) a Bend `String` is a JS string: matching `SCon` is `codePointAt` + `slice`, and `String.eq`/`String.cmp` rebuild both strings as they go. Comparing or walking long text char by char is quadratic on QuickJS (Android). Don't compare message texts per screen; find cheaper keys or keep the walk out of the per-screen path. | | 121 | +- `Bool.and(a, b)` in a recursive equality walks everything even after a mismatch. Carry the verdict as a parameter so the walk stops (`Eq.ops.go` in tiles.bend) and prove it once (`ops_go_sound`). | 118 | 122 |
| 119 | 123 | ## House rules | 120 | 124 |
| |
Collapse file Copy file name to clipboardExpand all lines: LAWS.bend +37Lines changed: 37 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -873,6 +873,43 @@ law frame_again_exact: | 873 | 873 | for +dy: U32 | 874 | 874 | {T.Frame.again(w, h, ops, base, T.FSome{w0, h0, T.Frame.make(w0, h0, old, base0)}, dy) == T.Frame.make(w, h, ops, base) : T.Tiles} | 875 | 875 |
| | 876 | +# a tile's image taken from what the parallel jobs drew is the tile drawn | | 877 | +# here, wherever its path leads in whatever jobs ran | | 878 | +law drawn_get_run: | | 879 | + for t: T.Jobs | | 880 | + for path: List<&2, Bool> | | 881 | + for +e: Nat | | 882 | + for +l: List<&2, R.Op> | | 883 | + for +base: Image | | 884 | + {T.Drawn.get(T.Jobs.run(t, e), path, e, l, base) == T.Tile.draw(e, l, base) : Image} | | 885 | + | | 886 | +# a plan filled from any jobs drawn in parallel is exactly the tiles | | 887 | +# Tiles.again gives, over any last tiles, with any scroll | | 888 | +law plan_fill_again: | | 889 | + for k: Nat | | 890 | + for +e: Nat | | 891 | + for +ops: List<&2, R.Op> | | 892 | + for +base: Image | | 893 | + for prev: T.Tiles | | 894 | + for +p: T.Past | | 895 | + for +rx: U32 | | 896 | + for +ry: U32 | | 897 | + for +n: U32 | | 898 | + for +off: Nat | | 899 | + for +t: T.Jobs | | 900 | + {T.Plan.fill(T.Tiles.plan(k, e, ops, base, prev, p, rx, ry, n), e, off, T.Jobs.run(t, e)) == T.Tiles.again(k, e, ops, base, prev, p, rx, ry, n) : T.Tiles} | | 901 | + | | 902 | +# the window's frame drawn in parallel is exactly Frame.again's (and so, | | 903 | +# by frame_again_exact, the frame drawn from scratch) | | 904 | +law frame_par_exact: | | 905 | + for +w: U32 | | 906 | + for +h: U32 | | 907 | + for +ops: List<&2, R.Op> | | 908 | + for +base: Image | | 909 | + for prev: T.Frames | | 910 | + for +dy: U32 | | 911 | + {T.Frame.par(w, h, ops, base, prev, dy) == T.Frame.again(w, h, ops, base, prev, dy) : T.Tiles} | | 912 | + | 876 | 913 | # the timeline's memo brought up to date is exactly the memo made from | 877 | 914 | # scratch, for any earlier entries | 878 | 915 | law tl_again_exact: | |
|