TableTower/tests/perf_typing.gd
RobinFiredrake 1735ed09fd Card threads, Morgan's welcome, and typing/scroll/wheel papercuts
- Card threads: a port on each card's bottom edge. Plain runs after any
  result (once the result's own threads finish); Otherwise runs only when
  no thread of the result ran. Saved as card_threads (LOGIC.md 3g).
- Typing on long cards no longer rebuilds the inspector or the card per
  key (~175 ms -> ~7 ms). Timing tool: tests/perf_typing.gd.
- "+ Add result" scrolls to the new row and focuses it.
- Mouse wheel zooms; Shift+wheel pans sideways; scrolling lists keep it.
- "SPREAD" caption over the switcher; Morgan's first-run welcome.
- docs/MECHANICS.md: checklist of table mechanics for planning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 10:41:13 -06:00

46 lines
1.7 KiB
GDScript

extends TestBase
## Times typing on a long card in Build mode: one key in a result's field on
## the card, in the card's name, and in the inspector's text field. Each number
## is the frame after the key (an idle frame is ~7 ms headless). Not part of
## the suite (the name doesn't start with test_). Run:
## SPREAD=/path/to/spread.json CARD=card_id \
## godot --headless --path . -s res://tests/perf_typing.gd -- --sample
func _init() -> void:
if not await start_main():
return
main.data.load_json(FileAccess.get_file_as_string(OS.get_environment("SPREAD")))
var t := main.data.get_table(OS.get_environment("CARD"))
t.collapsed = false
main.set_mode(Main.Mode.BUILD)
main._rebuild_cards()
await _frames(10)
var card: TableCard = main.card_for(t.id)
var eid := t.entries[mini(5, t.entries.size() - 1)].id
var row_edit: LineEdit = card.edit_ui.text_fields[eid]
var name_edit := _first_line_edit(card)
row_edit.grab_focus()
await _frames(5)
var insp_edit: LineEdit = (main.inspector.section_parts[eid]["fields"] as Dictionary)["text"]
for field: Array in [["card result", row_edit], ["card name", name_edit], ["inspector text", insp_edit]]:
var times: Array[String] = []
for i in 4:
var edit: LineEdit = field[1]
var started := Time.get_ticks_usec()
edit.text += "x"
edit.text_changed.emit(edit.text)
await process_frame
times.append("%.1f" % ((Time.get_ticks_usec() - started) / 1000.0))
print("PERF %s ms per key: %s" % [field[0], ", ".join(times)])
finish()
func _first_line_edit(n: Node) -> LineEdit:
for c in n.get_children():
if c is LineEdit and (c as LineEdit).editable:
return c
var found := _first_line_edit(c)
if found:
return found
return null