Skip to content

Conversation

@jserv
Copy link
Contributor

@jserv jserv commented Oct 17, 2025

This implements transform buffer cache in twin_pixmap_t to eliminate malloc and free on every transform compositing operation. Previous code allocated and freed the xform buffer for each transformation, creating unnecessary allocation overhead in the render loop.


Summary by cubic

Cached the transform buffer in twin_pixmap_t to stop per-frame malloc/free during compositing. This reduces allocation overhead in the render loop and should improve frame stability.

  • Refactors
    • Added xform_cache and xform_cache_size to twin_pixmap_t.
    • Reuse or grow the cached buffer in twin_pixmap_init_xform; twin_pixmap_free_xform is now a no-op.
    • Initialize cache in pixmap_create and pixmap_create_const; free it in twin_pixmap_destroy.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 3 files

Prompt for AI agents (all 1 issues)

Understand the root cause of the following 1 issues and fix them.


<file name="include/twin.h">

<violation number="1" location="include/twin.h:259">
`xform_cache_size` is stored in a 16-bit `twin_coord_t`, so large transform buffers overflow the cached size and lead to undersized allocations; please store this size in a wider type (e.g., size_t) and adjust the related calculations.</violation>
</file>

React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.

include/twin.h Outdated

/* Transform buffer cache for compositing operations */
void *xform_cache; /**< Cached xform buffer */
twin_coord_t xform_cache_size; /**< Cached xform buffer size in bytes */
Copy link

@cubic-dev-ai cubic-dev-ai bot Oct 17, 2025

Choose a reason for hiding this comment

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

xform_cache_size is stored in a 16-bit twin_coord_t, so large transform buffers overflow the cached size and lead to undersized allocations; please store this size in a wider type (e.g., size_t) and adjust the related calculations.

Prompt for AI agents
Address the following comment on include/twin.h at line 259:

<comment>`xform_cache_size` is stored in a 16-bit `twin_coord_t`, so large transform buffers overflow the cached size and lead to undersized allocations; please store this size in a wider type (e.g., size_t) and adjust the related calculations.</comment>

<file context>
@@ -253,6 +253,10 @@ typedef struct _twin_pixmap {
+
+    /* Transform buffer cache for compositing operations */
+    void *xform_cache;             /**&lt; Cached xform buffer */
+    twin_coord_t xform_cache_size; /**&lt; Cached xform buffer size in bytes */
 } twin_pixmap_t;
 
</file context>

✅ Addressed in 3a21d01

This implements transform buffer cache in twin_pixmap_t to eliminate
malloc and free on every transform compositing operation. Previous code
allocated and freed the xform buffer for each transformation, creating
unnecessary allocation overhead in the render loop.
@jserv jserv merged commit cdda0ea into main Oct 18, 2025
8 checks passed
@jserv jserv deleted the improve-malloc branch October 18, 2025 02:29
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