Skip to content

C: Use more sensible start capacity for hb_array#1381

Open
timkaechele wants to merge 1 commit intomarcoroth:mainfrom
timkaechele:lazy-errors-initialization
Open

C: Use more sensible start capacity for hb_array#1381
timkaechele wants to merge 1 commit intomarcoroth:mainfrom
timkaechele:lazy-errors-initialization

Conversation

@timkaechele
Copy link
Copy Markdown
Contributor

@timkaechele timkaechele commented Mar 14, 2026

This PR changes the start capacity of an array that previously had no capacity.

Instead of using 1, which only allocates a single slot, we allocate 8, which allows more room to grow.

Given that the hb_array only holds pointers to its items, the memory usage is negligible.

@github-actions github-actions bot added the c label Mar 14, 2026
@timkaechele timkaechele force-pushed the lazy-errors-initialization branch from a6b4334 to bb65e14 Compare March 18, 2026 16:48

if (array->capacity == 0) {
new_capacity = 1;
new_capacity = 8;
Copy link
Copy Markdown
Owner

@marcoroth marcoroth Mar 19, 2026

Choose a reason for hiding this comment

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

I'm wondering if this is really the right approach. Ideally we could have a lazy and/or shared empty array that only uses memory once for all instances. And only when we try to append errors, we convert it to a proper full array with a capacity. Otherwise on the happy path we would allocate a lot of memory that is never going to be used.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants