Run the endless-loop check after edits pause, not on every change

Roller.endless_cycles walks the whole board (about 30 ms on an 800-card
board) and ran on every keystroke in Build mode. It now runs 0.4 s after
edits stop, so a change costs about 0.4 ms instead of 34 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
RobinFiredrake 2026-11-08 19:03:39 -06:00
parent 292d45e179
commit 6ada00ad99

View file

@ -427,7 +427,7 @@ func _board_changed() -> void:
view_rev += 1
edit_rev += 1
_update_collapse_all()
_update_endless_chip()
_schedule_endless_check()
if mode == Mode.BUILD:
refresh_live()
@ -3347,3 +3347,20 @@ func _run_undo_cli(args: PackedStringArray) -> void:
ev.global_position = ev.position
get_viewport().push_input(ev)
await get_tree().process_frame
# ---------- Endless-loop check, debounced ----------
var _endless_timer: Timer
## The endless-loop check walks the whole board (about 30 ms on an 800-card
## board), so edits schedule it to run once typing pauses instead of on every
## keystroke.
func _schedule_endless_check() -> void:
if _endless_timer == null:
_endless_timer = Timer.new()
_endless_timer.one_shot = true
_endless_timer.wait_time = 0.4
_endless_timer.timeout.connect(_update_endless_chip)
add_child(_endless_timer)
_endless_timer.start()