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] Further optimizations for dedup improvement #83973

Closed
2 of 3 tasks
Tracked by #80938
kotlarmilos opened this issue Mar 27, 2023 · 4 comments · Fixed by #85908
Closed
2 of 3 tasks
Tracked by #80938

[mono][aot] Further optimizations for dedup improvement #83973

kotlarmilos opened this issue Mar 27, 2023 · 4 comments · Fixed by #85908
Assignees
Labels
area-Codegen-AOT-mono blocked Issue/PR is blocked on something - see comments
Milestone

Comments

@kotlarmilos
Copy link
Member

kotlarmilos commented Mar 27, 2023

Description

This issue tracks further optimizations for the introduced dedup improvement.

Build without a container assembly

By introducing #83511, container AOT module is loaded by using assembly name. Therefore, there is no need for additional AOT assembly in a bundle anymore.

UPDATE: With the current code, it would be a high effort to decouple AOT image and an associated assembly.

Runtime invoke wrappers on iOS

Current implementation doesn't cover cases where both shared method and its inflated instances could be deduplicated. During the compilation, the shared method is emitted in corresponding AOT module, while inflated instances are emitted in a container AOT module. During the runtime, the shared method can't be retrieved as it was searched in the container AOT module.

Here is an example. During the compilation, the following list of inflated instances emitted in the dedup AOT module.

(wrapper runtime-invoke) object <Module>:runtime_invoke_byte__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_byte (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_int__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_int__this___int_int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_int_int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_uint16__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_uint16 (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_bool__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_byte (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_sbyte__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_sbyte (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_char__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_uint16 (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_int16__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_int16 (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_uint__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_uint (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_long__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_long (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_ulong__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_long (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_intptr__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_intptr (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_uintptr__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_intptr (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_single__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_single (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_double__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_double (object,intptr,intptr,intptr)

During the runtime, (wrapper runtime-invoke) void object:runtime_invoke_dynamic (intptr,intptr,intptr,intptr) was searched in the dedup AOT module as it is RUNTIME_INVOKE_WRAPPER, but not emitted in the dedup AOT module. It could be addressed by updating mono_aot_get_method method to handle such cases. Alternative approach could be adding a dedup flag in MonoMethod struct but it looks like inefficient approach.

Investigate gshared methods emitted into the dedup AOT module

Dedup AOT module should contain extra methods and generic instances only. However, the following gshared methods are emitted in addition to its instances.

System_Numerics_Vector_As_TFrom_GSHAREDVT_TTo_GSHAREDVT_System_Numerics_Vector_1_TFrom_GSHAREDVT
System_Runtime_Intrinsics_Vector64_As_TFrom_GSHAREDVT_TTo_GSHAREDVT_System_Runtime_Intrinsics_Vector64_1_TFrom_GSHAREDVT
System_Runtime_Intrinsics_Vector128_As_TFrom_GSHAREDVT_TTo_GSHAREDVT_System_Runtime_Intrinsics_Vector128_1_TFrom_GSHAREDVT
System_Runtime_Intrinsics_Vector256_As_TFrom_GSHAREDVT_TTo_GSHAREDVT_System_Runtime_Intrinsics_Vector256_1_TFrom_GSHAREDVT

Tasks

  • Simplify build process by excluding dedup assembly
  • Deduplicate runtime invoke wrappers on iOS
  • Investigate gshared methods emitted into the dedup AOT module
@kotlarmilos kotlarmilos self-assigned this Mar 27, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Mar 27, 2023
@kotlarmilos kotlarmilos added this to the 8.0.0 milestone Mar 27, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Mar 27, 2023
@kotlarmilos kotlarmilos added untriaged New issue has not been triaged by the area owner and removed untriaged New issue has not been triaged by the area owner labels Mar 27, 2023
@kotlarmilos
Copy link
Member Author

To simplify the build process we could avoid generating an additional assembly as it is empty. However, assembly guid is required during AOT compilation and it seems to be generated when creating .dll. @vargaz is there an alternative?

@vargaz
Copy link
Contributor

vargaz commented Apr 4, 2023

We do need the assemby for aot compilation, we just don't need it at runtime.

@kotlarmilos
Copy link
Member Author

kotlarmilos commented Apr 4, 2023

Right, as you described it would simplify the AOT compilation, but with the current code, AOT images need an associated assembly.

@kotlarmilos
Copy link
Member Author

When runtime invoke wrappers are deduplicated, System.Runtime are failing on the ios-arm64 CI, even though they pass locally. The failure could be related to missing runtime invoke wrappers during application startup, and the error log may have been masked by a TCP failure. The tests have passed on tvos-arm64, which shouldn't differ from ios-arm64 on the CI.

Before merging the deduplication of runtime invoke wrappers on iOS, the CI should be updated to report any error logs that occurred during startup, as discussed in dotnet/arcade#11683.

@kotlarmilos kotlarmilos added the blocked Issue/PR is blocked on something - see comments label Apr 13, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label May 8, 2023
@kotlarmilos kotlarmilos modified the milestones: Future, 8.0.0 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 blocked Issue/PR is blocked on something - see comments
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants