Repository navigation
Conversation
Memory allocated its first 4 KiB in the constructor, with allocate_capacity(), the same realloc() call that grow_capacity() makes. Start with no capacity instead: the first growth allocates the memory in grow_capacity(), which already rounds the size up to whole pages, so every capacity stays as before and allocate_capacity() folds into grow_capacity(). Every access to the memory is behind a non-zero size, so it comes after a growth. A state that never grows its memory now allocates none. The life of a Memory takes 10 instructions instead of 301 when it is never grown, and 33 to 73 more when it is, from the out-of-line first growth (GCC 15, malloc(), realloc() and free() included). Baseline keeps one state for each call depth, Advanced creates one for each execution.
Contributor
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1795 +/- ##
==========================================
- Coverage 98.24% 98.24% -0.01%
==========================================
Files 186 186
Lines 17175 17173 -2
Branches 3921 3921
==========================================
- Hits 16873 16871 -2
Misses 233 233
Partials 69 69
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Memoryallocated its first 4 KiB in the constructor, withallocate_capacity(), the samerealloc()call thatgrow_capacity()makes. It now starts with no capacity, and its first growth allocates the memory ingrow_capacity(), which already rounds the size up to whole pages: every capacity stays as before, andallocate_capacity()folds intogrow_capacity(). Until the first growth the data pointer is null. Every access to the memory in the library is behind a non-zero size, so it comes after a growth.A state that never grows its memory now allocates none, and the first growth of one that does takes the out-of-line path, with
realloc()of a null pointer instead ofmalloc(). Instructions of the whole life of aMemory,malloc(),realloc()andfree()included, counted with callgrind (x86-64, GCC 15 and Clang 21):mstore(0x40, 0x80)Baseline keeps one execution state for each call depth for the life of the VM, so it pays either difference once per depth. Advanced creates a state for each execution. The machine code of the growths, the instructions and the interpreter loops is unchanged; only the state creation, in
VM::get_execution_state()and Advanced'sexecute(), loses themalloc()call and its out-of-memory check.