Skip to content
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 memory allocation for Array#push #789

Closed
wants to merge 1 commit into from

Conversation

bowenwang1996
Copy link
Contributor

Double the capacity of array when reallocating to avoid quadratically allocating memory. Fixes #788

@dcodeIO
Copy link
Member

dcodeIO commented Aug 23, 2019

It'd be more efficient to do this on the memory allocator level. The __realloc implementation of TLSF for instance does this already, taking advantage of the fact that it knows how much overhead a block has anyway, so it only has to copy when absolutely necessary. Ideally, the __realloc impl of the stub runtime would do the same, taking advantage of alignment (block sizes are 16 + n * 16) and doubling. For instance, if a block of size 8 is created, it's guaranteed to have 8 bytes overhead that it can reuse (by only updating .rtSize) before copying. The stub allocator can also try to resize the last segment indefinitely since it knows that everything after is free anyway.

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.

Array#push causes memory problems
2 participants