Skip to content

Reduce clipping memory usage and allocation #920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

tomcur
Copy link
Member

@tomcur tomcur commented Apr 17, 2025

The scratch strip buffer may be quite large when the render context has been used for rendering complex paths. If the clip geometry is simple, storing that buffer in the clip state has two downsides:

  • the buffer will have unused capacity, inflating the memory footprint of the renderer,
  • as the buffer is moved into the clip state, a new buffer has to be allocated, and for subsequent rendering of complex paths will have to grow large again.

This PR proposes keeping the original allocation for the scratch strip buffer and memcpy'ing the clip's strips to a new allocation of the right size. (As a side-effect the size of the Clip struct is reduced from 40 to 32 bytes.)

There are alternatives: the first downside could be alleviated by a shrink_to_fit, and allocator thrashing of the second downside could be reduced by allocating the new buffer with the same capacity as the old buffer. It's probably better to just keep the original allocation for the scratch buffer, though.

The scratch strip buffer may be quite large when the render context has
been used for rendering complex paths. If the clip geometry is simple,
storing that buffer in the clip state has two downsides:
- the buffer will have unused capacity, inflating the memory footprint
  of the renderer,
- as the buffer is moved into the clip state, a new buffer has to be
  allocated, and for subsequent rendering of complex paths will have to
  grow large again.

This PR proposes keeping the original allocation for the scratch strip
buffer and memcpy'ing the clip's strips to a new allocation of the right
size. (As a side-effect the size of the `Clip` struct is reduced from 40
to 32 bytes.)

There are alternatives: the first downside could be alleviated by a
`shrink_to_fit`, and allocator thrashing of the second downside could be
reduced by allocating the new buffer with the same capacity as the old
buffer. It's probably better to just keep the original allocation for
the scratch buffer, though.
Copy link
Contributor

@LaurenzV LaurenzV left a comment

Choose a reason for hiding this comment

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

I think that makes sense!

@tomcur tomcur added this pull request to the merge queue Apr 23, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 23, 2025
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