Skip to content

Commit

Permalink
feat(compiler)!: Reduce size of runtime heap (#1807)
Browse files Browse the repository at this point in the history
* feat(compiler): Reduce size of runtime heap

* update contrib docs

---------

Co-authored-by: Blaine Bublitz <[email protected]>
  • Loading branch information
ospencer and phated committed Apr 22, 2023
1 parent 8ccea28 commit 246f894
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/contributor/runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ When we speak of the Grain runtime, we largely mean the memory allocator, garbag

## The Runtime Heap

Currently, the Grain runtime heap spans half a WebAssembly page of memory. The low 1K of memory is reserved for Binaryen optimizations, the next few bytes are reserved for some static pointers (which we'll go over next), and the rest of half-page is space used for runtime allocations. It's important to note that this space is unmanaged. After all, we don't have a memory manager yet—we want to compile the memory manager. Allocations are done just by incrementing a bytes counter. This means that no space can be reclaimed—as such, runtime modules should do no dynamic allocations. Ideally, the only allocations that should occur are for the closures of top-level functions that are used by other modules.
Currently, the Grain runtime heap reserves 2048 bytes of WebAssembly memory. The low 1K of memory is reserved for Binaryen optimizations, the next few bytes are reserved for some static pointers (which we'll go over next), and the rest of the space is used for runtime allocations. It's important to note that this space is unmanaged. After all, we don't have a memory manager yet—we want to compile the memory manager. Allocations are done just by incrementing a bytes counter. This means that no space can be reclaimed—as such, runtime modules should do no dynamic allocations. Ideally, the only allocations that should occur are for the closures of top-level functions that are used by other modules.

## Static Runtime Pointers

Expand Down
2 changes: 1 addition & 1 deletion stdlib/runtime/malloc.gr
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let logMallocHeaderSize = 3n
*/
let mut heapSize = 0n

provide let _RESERVED_RUNTIME_SPACE = 0x4000n
provide let _RESERVED_RUNTIME_SPACE = 0x800n

/**
* The base the heap. The block at this address will be size 0 and
Expand Down

0 comments on commit 246f894

Please sign in to comment.