Skip to content

Conversation

@wyattgill9
Copy link

Summary

Optimizes buffer growth strategy by reducing unnecessary reallocations realloc() (calls) improving performance for large reads, with no small read difference

Changes: run.c

  • Changed buffer expansion logic for efficiency.
  • Reduces realloc calls, improving large read performance.

Code changed

if (bytes.len == capacity - 1) {
  capacity *= 2;
  bytes.buf = realloc(bytes.buf, capacity);
}

=>

if (bytes.len + 16 >= capacity) {  // Grow in larger increments
  capacity = capacity * 2 + 128;   // Avoid frequent realloc
  bytes.buf = realloc(bytes.buf, capacity);
}

I can tweak the exact numbers, but this is a good start

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