Skip to content

perf(framebuffer): avoid cloning during flush for every frame#153

Merged
j-g00da merged 1 commit intomainfrom
perf/avoid-framebuffer-clone-on-flush
Jan 30, 2026
Merged

perf(framebuffer): avoid cloning during flush for every frame#153
j-g00da merged 1 commit intomainfrom
perf/avoid-framebuffer-clone-on-flush

Conversation

@orhun
Copy link
Copy Markdown
Member

@orhun orhun commented Jan 29, 2026

In my tests, I experienced this problem after each Terminal::draw
call:

PanicInfo { message: memory allocation of 1073608832 bytes failed }

That's a whopping 1.0 GiB of allocation. This happens because the
&HeapBuffer iterator cloned the entire framebuffer on each flush,
allocating width × height × sizeof(C) bytes per frame.
My guess is, on 32-bit embedded targets this can overflow and appear
as a massive allocation request.

The fix is to have the iterator borrow the existing buffer and yield
copied pixels instead, eliminating heap allocations on every frame.

In my tests, I experienced this problem after each `Terminal::draw`
call:

```
PanicInfo { message: memory allocation of 1073608832 bytes failed }
```

That's a whopping 1.0 GiB of allocation. This happens because the
`&HeapBuffer` iterator cloned the entire framebuffer on each flush,
allocating `width × height × sizeof(C)` bytes per frame.
My guess is, on 32-bit embedded targets this can overflow and appear
as a massive allocation request.

The fix is to have the iterator borrow the existing buffer and yield
copied pixels instead, eliminating heap allocations on every frame.
@orhun orhun requested a review from j-g00da January 29, 2026 18:14
Copy link
Copy Markdown
Member

@j-g00da j-g00da left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Thanks :)

@j-g00da j-g00da merged commit 21018ed into main Jan 30, 2026
26 checks passed
@github-actions github-actions bot mentioned this pull request Jan 30, 2026
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.

2 participants