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

Separate RTS Builds (Incremental and Non-Incremental GC) #3913

Merged
merged 847 commits into from May 12, 2023

Conversation

luc-blaeser
Copy link
Contributor

@luc-blaeser luc-blaeser commented Mar 31, 2023

Separate RTS Builds (Incremental and Non-Incremental GC)

Using different memory layouts determined at compile time:

  • Incremental GC:
    • Extended header with forwarding pointer field.
    • Partitioned heap.
  • Non-incremental GC (copying, compacting, and generational GC):
    • Small header only comprising the object tag.
    • Linear heap.

Runtime System Changes

Separate RTS builds by introducing the feature "incremental_gc" for incremental GC memory layout.

Helper macros:

  • #[incremental_gc]: macro attribute, equivalent to #[cfg(feature = "incremental_gc")]
  • #[non_incremental_gc]: macro attribute, equivalent to #[cfg(not(feature = "incremental_gc"))]
  • is_incremental_gc!(): procedure macros, equivalent to cfg!(feature = "incremental_gc")

Different builds:

  • rts.wasm: Release build with non-incremental GCs (containing the copying, compacting, and generational GC).
  • rts-debug.wasm: Debug build with non-incremental GCs (containing the copying, compacting, and generational GC).
  • rts-incremental.wasm: Release build with only the incremental GC (no other GCs).
  • rts-incremental-debug.wasm: Debug build with only the incremental GC (no other GCs).

Compiler Changes

GC-dependent compilation:

  • Conditional header layout with or without forwarding pointer.
  • Linking the corresponding matching RTS build, with build-specific imports.

Switch based on the condition !Flags.gc_strategy == Flags.Incremental.

Performance

Comparing the the following designs:

  • Non-Incremental RTS: Original RTS in master branch without incremental GC changes.
  • Combined RTS: Combining incremental and non-incremental GC in one RTS build, PR: Incremental GC #3837
  • Separate RTS: This PR.

Binary Size

Size of the release RTS binary files.

GC Non-Incremental RTS Combined RTS Separate RTS
non-incremental 174 KB 194 KB 174 KB
incremental - 194 KB 175 KB

11% reduction.

Total allocations

GC benchmark results with dfx 0.13.1.
Total amount of allocated memory (heap size + reclaimed memory) at runtime, average across benchmark cases.

GC Non-Incremental RTS Combined RTS Separate RTS
copying 459 MB 496 MB 459 MB
compacting 459 MB 496 MB 459 MB
generational 480 MB 517 MB 480 MB
incremental - 502 MB 502 MB

For non-incremental GCs: 8% reduction compared to the combined RTS, same like non-incremental RTS.

Memory Size

GC benchmark results with dfx 0.13.1.
Allocated WASM memory size at runtime, average across benchmark cases.

GC Non-Incremental RTS Combined RTS Separate RTS
copying 271 MB 281 MB 271 MB
compacting 188 MB 195 MB 188 MB
generational 191 MB 201 MB 194 MB
incremental - 294 MB 294 MB

For non-incremental GCs: 4% reduction compared to the combined RTS, same like non-incremental RTS.

Total Instructions

GC benchmark results with dfx 0.13.1.
Number of executed instructions, average across benchmark cases.

GC Non-Incremental RTS Combined RTS Separate RTS
copying 2.05e10 2.12e10 2.07e10
compacting 2.20e10 2.24e10 2.21e10
generational 1.91e10 1.93e10 1.92e10
incremental - 1.95e10 1.95e10

For non-incremental GCs: Around 2% reduction compared to combined RTS, around 1%* overhead compared to non-incremental RTS.

Conclusion

Advantages of this PR:

  • Avoiding performance degrades for the classical GCs by introducing the incremental GC support.
  • Smaller binary sizes.

luc-blaeser and others added 30 commits February 23, 2023 19:41
Co-authored-by: Claudio Russo <claudio@dfinity.org>
Co-authored-by: Claudio Russo <claudio@dfinity.org>
src/codegen/compile.ml Outdated Show resolved Hide resolved
src/codegen/compile.ml Outdated Show resolved Hide resolved
src/codegen/compile.ml Outdated Show resolved Hide resolved
src/codegen/compile.ml Outdated Show resolved Hide resolved
Copy link
Contributor

@crusso crusso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But don't forget to fix those uses of physical equality

Base automatically changed from luc/incremental-gc to master May 12, 2023 09:55
@luc-blaeser luc-blaeser added the automerge-squash When ready, merge (using squash) label May 12, 2023
@mergify mergify bot merged commit 22f25d2 into master May 12, 2023
9 checks passed
@mergify mergify bot removed the automerge-squash When ready, merge (using squash) label May 12, 2023
@mergify mergify bot deleted the luc/separate-rts-builds branch May 12, 2023 12:30
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.

None yet

2 participants