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**
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.
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
existing value, only numbers, needs "unless already there" vs "every time, in order".
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,
119 threads; "New World" walks 54 cards, plus the 3–5× lifeform repeat). Profile Roller vs UI.
3. ~~Roll hitch~~ fixed (see "Known, not urgent").
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
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"
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.
- **Roll hitch (user report, 2026-11-11):** before certain groups show their results, the whole
app freezes for several frames. Not investigated yet; which groups is not pinned down. Likely
suspects: a long pipe chain rolled in one frame (Stage II's lifeform loop with nested
pipes), the rebuild of the result tree/thread nodes, or the why/describe text. Profile first
(Godot profiler, or time `Roller` vs. the board redraw) before changing anything.
- **Roll hitch: fixed 2026-11-14.** Measured on Perilous Void (headless, fast roll of "New
World"): roll logic ~3 ms, but the app took 3.4 s after it. Causes: every relight restyled every
row and column cell (font overrides make RichTextLabels re-measure; ~11 ms per row), and the
Earlier tab rebuilt every history row each render (long texts, ~25 ms each, growing per roll).
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.
## 5. Working on it

View file

@ -7,6 +7,9 @@ var main: Main
var scroll: ScrollContainer
var _rows: VBoxContainer
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:
@ -26,24 +29,42 @@ func setup(p_main: Main) -> void:
func render() -> void:
for c in _rows.get_children():
_rows.remove_child(c)
c.queue_free()
var kept: Array = []
for rec in main.history:
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()
scroll.visible = not _empty.visible
scroll.scroll_vertical = 0
for rec in main.history:
var row := HBoxContainer.new()
row.add_theme_constant_override("separation", 8)
var time := Style.make_label(clock(rec["time"]), Style.body(), 14, Style.ON_BG_MUTED)
time.custom_minimum_size = Vector2(44, 0)
time.size_flags_vertical = SIZE_SHRINK_BEGIN
row.add_child(time)
var line := RichText.label(earlier_line(rec), 14, Style.ON_BG, false)
line.size_flags_horizontal = SIZE_EXPAND_FILL
RichText.hook_hover(line, main)
row.add_child(line)
_rows.add_child(row)
func _make_row(rec: Dictionary) -> HBoxContainer:
var row := HBoxContainer.new()
row.add_theme_constant_override("separation", 8)
var time := Style.make_label(clock(rec["time"]), Style.body(), 14, Style.ON_BG_MUTED)
time.custom_minimum_size = Vector2(44, 0)
time.size_flags_vertical = SIZE_SHRINK_BEGIN
row.add_child(time)
var line := RichText.label(earlier_line(rec), 14, Style.ON_BG, false)
line.size_flags_horizontal = SIZE_EXPAND_FILL
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

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.
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()
# 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)
l.add_theme_color_override("default_color", Style.MUTED if passed else Style.INK)
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)
if int(p["index"]) % 2 == 1 and card.main.local_state.striped_rows():
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)
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"]
if num:
num.add_theme_color_override("font_color", Style.INK if state == RowState.LIT else Style.MUTED)