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

[mono][aot] Avoid generating rgctx fetch trampolines in generic sharing #82906

Closed
Tracked by #80938
kotlarmilos opened this issue Mar 2, 2023 · 4 comments · Fixed by #86583
Closed
Tracked by #80938

[mono][aot] Avoid generating rgctx fetch trampolines in generic sharing #82906

kotlarmilos opened this issue Mar 2, 2023 · 4 comments · Fixed by #86583
Assignees
Labels
area-Codegen-AOT-mono size-reduction Issues impacting final app size primary for size sensitive workloads
Milestone

Comments

@kotlarmilos
Copy link
Member

kotlarmilos commented Mar 2, 2023

Description

For a generic sharing methods, size of variable types is only known at runtime and AOT compiler cannot allocate static stack slots for them. Instead, a stack area is allocated at runtime and address is dynamically computed. The information required for this is either stored in the vtable or in a MonoMethodRuntimeGenericContext structure. In the structure, the offsets are known at compile time so it can generate inline code. However, in the vtable, they are assigned at runtime, so rgctx fetch trampolines are used to read it.

In order to improve size of an AOT image, the idea is to pass the structure to all gshared methods, and thus avoid generating rgctx fetch trampolines. As it requires a lot of changes, an experimental data on size and speed should be retrieved before considering the implementation.

@kotlarmilos kotlarmilos added area-Codegen-AOT-mono size-reduction Issues impacting final app size primary for size sensitive workloads labels Mar 2, 2023
@kotlarmilos kotlarmilos added this to the Future milestone Mar 2, 2023
@kotlarmilos kotlarmilos self-assigned this Mar 2, 2023
@ghost
Copy link

ghost commented Mar 2, 2023

Tagging subscribers to 'size-reduction': @eerhardt, @SamMonoRT, @marek-safar
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

For a generic sharing methods, size of variable types is only known at runtime and AOT compiler cannot allocate static stack slots for them. Instead, a stack area is allocated at runtime and address is dynamically computed. The information required for this is either stored in the vtable or in a MonoMethodRuntimeGenericContext structure. In the structure, the offsets are known at compile time so it can generate inline code. However, in the vtable, they are assigned at runtime, so rgctx fetch trampolines to read it.

In order to improve size of an AOT image, the idea is to pass the structure to all gshared methods, and thus avoid generating rgctx fetch trampolines. As it requires a lot of changes, an experimental data on size and speed should be retrieved before considering the implementation.

Author: kotlarmilos
Assignees: kotlarmilos
Labels:

area-Codegen-AOT-mono, size-reduction

Milestone: Future

@vargaz
Copy link
Contributor

vargaz commented Mar 9, 2023

This PR can be used to test this:
#82981

@kotlarmilos
Copy link
Member Author

@vargaz I've tested the change on HelloiOS app and size reduction could be about 700kb. About 1k rgctx fetch trampolines are gone, but there are still some rgctx fetch calls. Symbols from binaries before and after the change are attached.

bloaty-symbol-compare.txt
bloaty-symbols-before-change.txt
bloaty-symbols-after-change.txt

@kotlarmilos
Copy link
Member Author

@vargaz I repeated the measurements but didn't get any size difference. What could be the case?

@kotlarmilos kotlarmilos modified the milestones: Future, 8.0.0 May 22, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label May 22, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label May 24, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Codegen-AOT-mono size-reduction Issues impacting final app size primary for size sensitive workloads
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants