Skip to content

[P3] render_event_drawer() rebuilds a fresh array + join() on every event_rev bump #361

Description

@itsmiso-ai

Ask: Cache the event-drawer expanded-log lines in main.gd render_event_drawer() so the per-render string-array allocation only happens when the event list changes rather than on every event_rev bump.
Expected files: scripts/main.gd

Problem: scripts/main.gd:1829-1848 render_event_drawer() runs whenever sim.event_rev ticks. The collapsed-label branch sets a single event_drawer_label.text and is cheap. The expanded-log branch, however, builds a fresh lines := [] Array, runs six "t%02d %s" % [...] format calls, then calls "\n".join(lines) to assign to event_drawer_log.text. Each event_rev bump (every push_event, which fires on every ambient drop, milestone completion, goal completion, recruit, build queue, build finish, food upkeep tick, break completion, and stale-reservation cleanup) pays that allocation cost. The 2026-07-15 audit (#279 finding 8) flagged this as a future concern; it has not been addressed.

Evidence:

  • scripts/main.gd:1829func render_event_drawer() -> void: — early-return gate at _drawer_event_rev == sim.event_rev
  • scripts/main.gd:1845 — comment Update expanded log with recent history (last 6 events)
  • scripts/main.gd:1846var lines := [] — array allocated per call
  • scripts/main.gd:1847lines.append("t%02d %s" % [int(entry.tick), String(entry.get("text", ""))]) — format string per event in the loop
  • scripts/main.gd:1848event_drawer_log.text = "\n".join(lines) if not lines.is_empty() else "No events yet." — second string allocation from join()
  • The gate only prevents rerun when nothing changes; event_rev increments on every push_event, so the churn scales with how busy the colony is
  • 2026-07-15 audit (Weekly tech debt audit: windowstead - 2026-07-15 #279 finding 8) called this out: "render_event_drawer() creates string arrays every tick" — still valid

Acceptance:

  • render_event_drawer caches the joined drawer text (e.g. cached_text: String + last_rendered_size: int keyed by event list identity) and only recomputes when the last 6 events actually changed
  • Inactive colonies (no recent pushes) do zero allocation in render_event_drawer beyond the event_rev compare
  • Visual output for the drawer matches the current behaviour byte-for-byte (event_drawer_log.text is the same string for the same event list)
  • A simple test scenario: queue a push_event, assert the cached text updated once; idle for a tick, assert no recomputation

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    auditAudit, review, or investigation work.priority/p3Low priority.status/readyReady for Dispatch worker pickup.type/choreChore or maintenance.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions