Roll timing tool (tests/perf_roll.gd, outside the suite)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
RobinFiredrake 2026-11-14 13:48:08 -06:00
parent ac85122541
commit c341790d1a
3 changed files with 50 additions and 2 deletions

View file

@ -166,8 +166,8 @@ that works on any theme (solid background, stronger text, thicker borders, no ef
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.
per roll, flat (most of it is the 2–3 questions, each relighting ~70 ms first). Timing tool:
`tests/perf_roll.gd` (SPREAD=… CARD=…; not in the suite).
- Known gaps: ARCHITECTURE.md §7.
## 5. Working on it

47
tests/perf_roll.gd Normal file
View file

@ -0,0 +1,47 @@
extends TestBase
## Times rolling one card on a big spread: the roll logic alone, then the
## whole app roll (fast), then the parts of the screen update after it.
## Not part of the suite (the name doesn't start with test_). Run:
## SPREAD=/path/to/spread.json CARD=start \
## godot --headless --path . -s res://tests/perf_roll.gd -- --sample
## (--sample keeps the app from reading or writing saved spreads.)
func _init() -> void:
if not await start_main():
return
var card_id := OS.get_environment("CARD") if OS.get_environment("CARD") != "" else "start"
main.prompt_hook = func(req: Dictionary) -> Variant:
return 0 if not (req.get("options", []) as Array).is_empty() else req.get("default", 1)
main.data.load_json(FileAccess.get_file_as_string(OS.get_environment("SPREAD")))
main.persistent_vars.clear()
main._rebuild_cards()
await _frames(10)
var logic_ms: Array[float] = []
for seed_value in 10:
var rng := RandomNumberGenerator.new()
rng.seed = seed_value
var ctx := Roller.new_context(main.data, rng, {}, {})
ctx.prompt = main.prompt_hook
var started := Time.get_ticks_usec()
await Roller.roll_async(main.data, card_id, ctx)
logic_ms.append((Time.get_ticks_usec() - started) / 1000.0)
print("PERF logic ms: ", logic_ms)
for seed_value in 6:
main.rng.seed = 100 + seed_value
var started := Time.get_ticks_usec()
await main.rolling.start_roll(card_id, true)
var rolled := Time.get_ticks_usec()
await process_frame
print("PERF app roll %.1f ms, next frame %.1f ms, steps %d" % [(rolled - started) / 1000.0,
(Time.get_ticks_usec() - rolled) / 1000.0, (main.current["all"] as Array).size()])
var marks: Array[int] = [Time.get_ticks_usec()]
main._refresh_lit()
marks.append(Time.get_ticks_usec())
main.refresh_live()
marks.append(Time.get_ticks_usec())
main.tray.render()
marks.append(Time.get_ticks_usec())
print("PERF parts: relight %.1f ms, live cards %.1f ms, tray %.1f ms" % [(marks[1] - marks[0]) / 1000.0,
(marks[2] - marks[1]) / 1000.0, (marks[3] - marks[2]) / 1000.0])
finish()

1
tests/perf_roll.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://dh0lx2kdd1pje