Skip to content

Commit 9c4e4e3

Browse files
committed
Schematic sheets: read each row once
Hier.read.go passed the rest of the list to both arms of Bool.pick, and Bool.pick takes its arguments evaluated, so every line read the rest twice: 2^n row reads for n sheets. The web viewer reads the project's sheets on every render (View.sheets, twice), so with a 19-sheet schematic each render of the page spent seconds in it, and the Schematic tab took most of a minute to show. Each row is now read once (Hier.read.keep takes the rest already read), and View.sheets reads the sheets once per render. The phones and the window read sheets through the same Hier.read. hier_test: forty sheets read back (41 rows) -- killed at 60 s before, the whole test now runs in 0.7 s.
1 parent 8a3b63a commit 9c4e4e3

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

‎src/core/hier.bend‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,21 @@ def Hier.field(+fs: List<&2, String>, +i: Nat) -> String:
294294
def Hier.read.row(+fs: List<&2, String>) -> Row:
295295
Row{Maybe.default(&2, Nat, Nat.read(Hier.field(fs, 0n)), 0n), Hier.field(fs, 2n), Hier.field(fs, 3n), String.eq(Hier.field(fs, 1n), "1")}
296296

297+
# a line's row ahead of the rest (a blank line has none); the rest is read
298+
# once and passed in, as Bool.pick would read it in both of its arms
299+
def Hier.read.keep(empty: Bool, +l: String, rest: List<&2, Row>) -> List<&2, Row>:
300+
match empty:
301+
case True{}:
302+
rest
303+
case False{}:
304+
Hier.read.row(String.split(l, '\t')) <> rest
305+
297306
def Hier.read.go(ls: List<&2, String>) -> List<&2, Row>:
298307
match ls:
299308
case Nil{}:
300309
Nil{}
301310
case +l <> +t:
302-
Bool.pick(List<&2, Row>, String.is_empty(l), Hier.read.go(t), Hier.read.row(String.split(l, '\t')) <> Hier.read.go(t))
311+
Hier.read.keep(String.is_empty(l), l, Hier.read.go(t))
303312

304313
def Hier.read(+s: String) -> List<&2, Row>:
305314
Hier.read.go(String.split(s, '\n'))

‎src/web/view.bend‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,9 +1425,13 @@ def View.sheet.chips(rs: List<&2, HI.Row>, +i: Nat, +cur: String) -> List<&2, D.
14251425
D.Dom.button(Bool.pick(String, String.eq(Bool.pick(String, Nat.is_eq(i, 0n), "", f), cur), "on", ""), "view-sheet", Bool.pick(String, Nat.is_eq(i, 0n), "", f), f,
14261426
Bool.pick(String, Nat.is_eq(i, 0n), "Top sheet", String.repeat("› ", d) ++ n)) <> View.sheet.chips(t, 1n+i, cur)
14271427

1428+
def View.sheets.of(+rs: List<&2, HI.Row>, +u: U.Ui) -> List<&2, D.Node>:
1429+
Bool.pick(List<&2, D.Node>, Nat.is_gt(List.length(&2, HI.Row, rs), 1n),
1430+
View.sheet.chips(rs, 0n, U.Ui.view_get(u, "view.path")), [D.Dom.span("what", "The project's schematic")])
1431+
1432+
# the project's sheets, read once per render
14281433
def View.sheets(+u: U.Ui) -> List<&2, D.Node>:
1429-
Bool.pick(List<&2, D.Node>, Nat.is_gt(List.length(&2, HI.Row, HI.Hier.read(U.Ui.info(u, "sheets:" ++ U.Ui.root(u)))), 1n),
1430-
View.sheet.chips(HI.Hier.read(U.Ui.info(u, "sheets:" ++ U.Ui.root(u))), 0n, U.Ui.view_get(u, "view.path")), [D.Dom.span("what", "The project's schematic")])
1434+
View.sheets.of(HI.Hier.read(U.Ui.info(u, "sheets:" ++ U.Ui.root(u))), u)
14311435

14321436
# the Layers menu (core/layers.bend): each layer shown by default, in
14331437
# KiCad's order (plot2d.js hides those the file has nothing on), a row of

‎test/hier_test.bend‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,23 @@ def Show.maybe(m: Maybe<&2, Nat>) -> String:
3333
def sch() -> String:
3434
"(kicad_sch (version 20231120)\n (wire (pts (xy 0 0) (xy 1 1)))\n (sheet (at 10 10) (size 20 20) (uuid \"u1\")\n (property \"Sheetname\" \"Power\" (at 10 9 0))\n (property \"Sheetfile\" \"power.kicad_sch\" (at 10 31 0)))\n (sheet (at 40 10) (size 20 20) (uuid \"u2\")\n (property \"Sheet name\" \"IO\" (at 40 9 0))\n (property \"Sheet file\" \"io/io.kicad_sch\" (at 40 31 0))))\n"
3535

36+
# n sheet rows as Hier.show writes them, one per line
37+
def many(n: Nat) -> String:
38+
match n:
39+
case 0n:
40+
"0\t0\ttop.kicad_sch\t/p/top.kicad_sch"
41+
case 1n+k:
42+
many(k) ++ "\n1\t0\tsheet\t/p/sheet.kicad_sch"
43+
3644
def main() -> IO(Unit):
3745
do IO<Unit>:
3846
+rs : List<&2, H.Row> = H.Hier.rows(tab(), "/p/top.kicad_sch")
3947
C.Check.str("rows", H.Hier.show(rs),
4048
"0\t0\ttop.kicad_sch\t/p/top.kicad_sch\n1\t0\tpower\t/p/power.kicad_sch\n2\t1\tagain\t/p/top.kicad_sch\n1\t0\tio\t/p/io/io.kicad_sch\n2\t0\tadc\t/p/io/adc.kicad_sch")
4149
C.Check.str("text round trip", H.Hier.show(H.Hier.read(H.Hier.show(rs))), H.Hier.show(rs))
50+
# each row is read once: 40 rows come back at once (reading the rest
51+
# twice per row took 2^n reads, minutes at 30 sheets)
52+
C.Check.str("forty sheets read", Nat.show(List.length(&2, H.Row, H.Hier.read(many(40n)))), "41")
4253
C.Check.str("chain of adc", Show.nats(H.Hier.chain(rs, 4n)), "0 3 4 ")
4354
C.Check.str("chain of root", Show.nats(H.Hier.chain(rs, 0n)), "0 ")
4455
C.Check.str("parent of adc", Nat.show(H.Hier.parent(rs, 4n)), "3")

0 commit comments

Comments
 (0)