Roll speed: skip restyling unchanged rows and cells, reuse Earlier rows

On the Perilous Void spread a fast roll's screen update took 3.4 s (the
roll logic itself ~3 ms). Every relight restyled every row and column
cell, and the Earlier tab rebuilt every history row. Now about 240 ms,
and it no longer grows with each roll.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
RobinFiredrake 2026-11-14 13:47:03 -06:00
parent 9d550408d8
commit ac85122541
4 changed files with 59 additions and 24 deletions

View file

@ -125,14 +125,15 @@ that works on any theme (solid background, stronger text, thicker borders, no ef
**Playtest findings (2026-11-14), proposed order; the user may reorder** **Playtest findings (2026-11-14), proposed order; the user may reorder**
1. ~~Size audit batch 2~~ done. 1. ~~Size audit batch 2~~ done.
2. Data bugs: Ledger entries live only in local state (`state.json` variables), so copies, 2. ~~Data bugs~~ done 2026-11-14 (Ledger `members` on the card, group colour on import,
grouping over open groups nests them, Add to list fixes + Allow repeats, combine rows per
column). Original notes: Ledger entries live only in local state (`state.json` variables), so copies,
exports and imports lose them, and the spread can't add entries: store them on the card. exports and imports lose them, and the spread can't add entries: store them on the card.
JSON import drops group `color`. Making a group over open groups steals their cards (leaves JSON import drops group `color`. Making a group over open groups steals their cards (leaves
empty groups); nesting works only with collapsed groups. "Add to list": can't pick an empty groups); nesting works only with collapsed groups. "Add to list": can't pick an
existing value, only numbers, needs "unless already there" vs "every time, in order". existing value, only numbers, needs "unless already there" vs "every time, in order".
Rerolls apply to all columns (make per-column, all-columns optional). Rerolls apply to all columns (make per-column, all-columns optional).
3. Roll hitch: shows on both Perilous Void copies. The spread is big (152 cards, 1,184 results, 3. ~~Roll hitch~~ fixed (see "Known, not urgent").
119 threads; "New World" walks 54 cards, plus the 3–5× lifeform repeat). Profile Roller vs UI.
4. Themes: frame corners jump on resize and float off the bottom (10 themes; one shared bug); 4. Themes: frame corners jump on resize and float off the bottom (10 themes; one shared bug);
Terminal edges and group corners flicker when zoomed out; group corners too hard to see in Terminal edges and group corners flicker when zoomed out; group corners too hard to see in
most themes (make bigger, outlined; one fixed default colour across themes; full colour most themes (make bigger, outlined; one fixed default colour across themes; full colour
@ -160,11 +161,13 @@ that works on any theme (solid background, stronger text, thicker borders, no ef
- Small ideas from the Perilous Void spread: an empty list shows blank in a sheet (no "none" - Small ideas from the Perilous Void spread: an empty list shows blank in a sheet (no "none"
default); a value change that should apply when a later value is rolled (Shattered lowers default); a value change that should apply when a later value is rolled (Shattered lowers
atmosphere after Gas/Life were already decided) has no clean form. atmosphere after Gas/Life were already decided) has no clean form.
- **Roll hitch (user report, 2026-11-11):** before certain groups show their results, the whole - **Roll hitch: fixed 2026-11-14.** Measured on Perilous Void (headless, fast roll of "New
app freezes for several frames. Not investigated yet; which groups is not pinned down. Likely World"): roll logic ~3 ms, but the app took 3.4 s after it. Causes: every relight restyled every
suspects: a long pipe chain rolled in one frame (Stage II's lifeform loop with nested row and column cell (font overrides make RichTextLabels re-measure; ~11 ms per row), and the
pipes), the rebuild of the result tree/thread nodes, or the why/describe text. Profile first Earlier tab rebuilt every history row each render (long texts, ~25 ms each, growing per roll).
(Godot profiler, or time `Roller` vs. the board redraw) before changing anything. Now rows/cells skip restyling when their look is unchanged, and Earlier reuses its rows: ~240 ms
per roll, flat. Timing script: copy the one in this session's scratch (`test_scratch_perf.gd`
pattern: TestBase + start_roll + per-part timers) if it comes back.
- Known gaps: ARCHITECTURE.md §7. - Known gaps: ARCHITECTURE.md §7.
## 5. Working on it ## 5. Working on it

View file

@ -7,6 +7,9 @@ var main: Main
var scroll: ScrollContainer var scroll: ScrollContainer
var _rows: VBoxContainer var _rows: VBoxContainer
var _empty: Label var _empty: Label
## The rows built so far: [record, row], so a render only builds rows for new
## rolls (long results make each row slow to build).
var _built: Array = []
func setup(p_main: Main) -> void: func setup(p_main: Main) -> void:
@ -26,24 +29,42 @@ func setup(p_main: Main) -> void:
func render() -> void: func render() -> void:
for c in _rows.get_children(): var kept: Array = []
_rows.remove_child(c) for rec in main.history:
c.queue_free() var row: Control = null
for pair: Array in _built:
if is_same(pair[0], rec):
row = pair[1]
break
if row == null:
row = _make_row(rec)
_rows.add_child(row)
kept.append([rec, row])
for pair: Array in _built:
if not kept.any(func(other: Array) -> bool: return is_same(other[1], pair[1])):
_rows.remove_child(pair[1])
(pair[1] as Node).queue_free()
for i in kept.size():
if (kept[i][1] as Node).get_index() != i:
_rows.move_child(kept[i][1], i)
_built = kept
_empty.visible = main.history.is_empty() _empty.visible = main.history.is_empty()
scroll.visible = not _empty.visible scroll.visible = not _empty.visible
scroll.scroll_vertical = 0 scroll.scroll_vertical = 0
for rec in main.history:
var row := HBoxContainer.new()
row.add_theme_constant_override("separation", 8) func _make_row(rec: Dictionary) -> HBoxContainer:
var time := Style.make_label(clock(rec["time"]), Style.body(), 14, Style.ON_BG_MUTED) var row := HBoxContainer.new()
time.custom_minimum_size = Vector2(44, 0) row.add_theme_constant_override("separation", 8)
time.size_flags_vertical = SIZE_SHRINK_BEGIN var time := Style.make_label(clock(rec["time"]), Style.body(), 14, Style.ON_BG_MUTED)
row.add_child(time) time.custom_minimum_size = Vector2(44, 0)
var line := RichText.label(earlier_line(rec), 14, Style.ON_BG, false) time.size_flags_vertical = SIZE_SHRINK_BEGIN
line.size_flags_horizontal = SIZE_EXPAND_FILL row.add_child(time)
RichText.hook_hover(line, main) var line := RichText.label(earlier_line(rec), 14, Style.ON_BG, false)
row.add_child(line) line.size_flags_horizontal = SIZE_EXPAND_FILL
_rows.add_child(row) RichText.hook_hover(line, main)
row.add_child(line)
return row
## One Earlier row: "Root: a → b → c", with only the last few steps of a long ## One Earlier row: "Root: a → b → c", with only the last few steps of a long

View file

@ -156,6 +156,12 @@ func _show_cell(c: Dictionary) -> void:
# "Roll each column separately": a lit row's other cells weren't rolled. # "Roll each column separately": a lit row's other cells weren't rolled.
var passed := not lit and card.table.column_rolls == RollTable.COLUMNS_EACH \ var passed := not lit and card.table.column_rolls == RollTable.COLUMNS_EACH \
and card.main.is_entry_lit(card.table.id, e.id) and not _lit_columns().is_empty() and card.main.is_entry_lit(card.table.id, e.id) and not _lit_columns().is_empty()
# Restyling makes the text be measured again (slow on big spreads), so a
# cell that already looks this way is left alone.
var look := "%s|%s" % [lit, passed]
if str(c.get("applied_look", "")) == look:
return
c["applied_look"] = look
RichText.set_fonts(l, 15, true, lit) RichText.set_fonts(l, 15, true, lit)
l.add_theme_color_override("default_color", Style.MUTED if passed else Style.INK) l.add_theme_color_override("default_color", Style.MUTED if passed else Style.INK)
var box: PanelContainer = c["box"] var box: PanelContainer = c["box"]

View file

@ -277,8 +277,13 @@ func set_row_state(eid: String, state: RowState) -> void:
var k := int(state) + (3 if eid == card.selected_entry() else 0) var k := int(state) + (3 if eid == card.selected_entry() else 0)
if int(p["index"]) % 2 == 1 and card.main.local_state.striped_rows(): if int(p["index"]) % 2 == 1 and card.main.local_state.striped_rows():
k += 6 k += 6
(card.rows[eid] as PanelContainer).add_theme_stylebox_override("panel", _row_styles[k]) # Restyling a row makes its text be measured again, which is slow on big
# spreads, so a row that already looks this way is left alone.
card.edit_ui.sync_delete(eid) card.edit_ui.sync_delete(eid)
if int(p.get("applied_style", -1)) == k:
return
p["applied_style"] = k
(card.rows[eid] as PanelContainer).add_theme_stylebox_override("panel", _row_styles[k])
var num: Label = p["num"] var num: Label = p["num"]
if num: if num:
num.add_theme_color_override("font_color", Style.INK if state == RowState.LIT else Style.MUTED) num.add_theme_color_override("font_color", Style.INK if state == RowState.LIT else Style.MUTED)