-
-
Notifications
You must be signed in to change notification settings - Fork 667
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
Improve stub RT reallocation #790
Conversation
btw. Analysing static-array.optimized.wat I see all memory runtime methods but this test use |
Seems the chain there is: |
Yeah. Forgot about |
Now also deals with last blocks, either
|
Going to merge if no objections. @MaxGraey would you mind taking a look before I do? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
if (size > BLOCK_MAXSIZE) unreachable(); | ||
maybeGrowMemory(ptr + size); | ||
} else { // copy to new block at least double the size | ||
let newPtr = __alloc(max<usize>(size, actualSize << 1), block.rtId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this work?
We allocate max<usize>(size, actualSize << 1)
, but in line 56 we set block.rtSize = size
, so the next call to realloc will look at previous size
and not the allocated capacity, and allocate again.
What am I missing?
potentially fixes #788
potentially fixes #789
Previously, if a memory block didn't fit anymore upon __realloc, the stub RT would reallocate to exactly the requested size, which is super inefficient since stub can't free and would waste lots of memory in any scenario reallocating multiple times (e.g. when filling a buffer). Instead, it now tries to at least double the capacity when wasting memory, to subsequently waste less.