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

RFC 0004: HEAP escape analysis #4

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Conversation

ysbaddaden
Copy link
Collaborator

@ysbaddaden ysbaddaden commented Feb 6, 2024

Add an optimization pass to the compiler to detect places where a class instantiation could happen on the stack rather than the GC HEAP.

Preview: https://github.com/crystal-lang/rfcs/blob/rfc-heap-escape-analysis/text/0004-heap-escape-analysis.md

Add an optimization pass to the compiler to detect places where a class instantiation could happen on the stack rather than the GC HEAP.
@ysbaddaden ysbaddaden self-assigned this Feb 6, 2024
@ysbaddaden ysbaddaden marked this pull request as draft February 6, 2024 13:28
text/0004-heap-escape-analysis.md Outdated Show resolved Hide resolved
text/0004-heap-escape-analysis.md Outdated Show resolved Hide resolved
Co-authored-by: Johannes Müller <[email protected]>
text/0004-heap-escape-analysis.md Outdated Show resolved Hide resolved
text/0004-heap-escape-analysis.md Outdated Show resolved Hide resolved

# Drawbacks

Some objects would now be allocated on the stack, which are GC roots that must be scanned conservatively and can't scan precisely. This may have negatively impact GC performance when we implement semi-conservative marking (conservative marking of GC roots _yet_ precise marking of HEAP allocated objects).
Copy link

Choose a reason for hiding this comment

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

I think it might be possible to reuse a lot of the escape analysis architecture to implement a shadow stack for each fiber which contains only roots. This could be both precise and a far smaller stack than the actual program stack for the GC to scan. Especially given the stack usage will grow when escape analysis is turned on.

I don't know how that tradeoff compares to the LLVM built in stackmap generator, but it's an idea.

@straight-shoota straight-shoota changed the title RFC 0004 : HEAP escape analysis RFC 0004: HEAP escape analysis Feb 8, 2024
Co-authored-by: Linus Sellberg <[email protected]>
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

4 participants