Skip to content

Conversation

jserv
Copy link
Contributor

@jserv jserv commented Oct 16, 2025

This implements span buffer cache in twin_screen_t to eliminate malloc and free on every screen update. Previous code allocated and freed the span buffer for each frame, creating unnecessary allocation overhead in the render loop.

Previous behavior:

  • malloc() span buffer at start of twin_screen_update()
  • free() span buffer at end of function
  • Repeated every frame, creating allocation churn

New behavior:

  • Allocate once, cache in screen->span_cache
  • Reuse buffer if current width fits
  • Realloc only when larger width needed
  • Free cache only on screen destruction

Summary by cubic

Caches the span buffer in twin_screen_t to remove per-frame malloc/free during screen updates, reducing allocation churn. Adds memory profiling to tools/perf to measure RSS and peak usage.

  • Refactors

    • Add span_cache and span_cache_width to twin_screen_t; reuse the buffer across frames.
    • Realloc only when width grows; free the cache on screen destroy.
  • New Features

    • Memory profiling mode in tools/perf with RSS delta and peak stats for common operations.
    • Fallback ARGB32 pixmap if assets/tux.png is missing.

This implements span buffer cache in twin_screen_t to eliminate malloc
and free on every screen update. Previous code allocated and freed the
span buffer for each frame, creating unnecessary allocation overhead in
the render loop.

Previous behavior:
- malloc() span buffer at start of twin_screen_update()
- free() span buffer at end of function
- Repeated every frame, creating allocation churn

New behavior:
- Allocate once, cache in screen->span_cache
- Reuse buffer if current width fits
- Realloc only when larger width needed
- Free cache only on screen destruction
cubic-dev-ai[bot]

This comment was marked as resolved.

@jserv jserv merged commit e553031 into main Oct 16, 2025
8 checks passed
@jserv jserv deleted the perf/alloc-overhead branch October 16, 2025 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant