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

[instantiation linking] Optimize aot func inst list #4018

Conversation

lum1n0us
Copy link
Collaborator

…pawned' for clarity in deinstantiation functions
…conv_wasm_c_api and call_conv_raw in WASM function structures
…structure and improving function import handling
extra->function_count = module->import_func_count + module->func_count;
if (extra->function_count > 0) {
extra->import_functions =
functions_instantiate(module_inst, module, imports, import_count,
Copy link
Contributor

Choose a reason for hiding this comment

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

how about renaming it to import_functions_instantiate?

{
AOTFunctionInstance *function = runtime_malloc(
sizeof(AOTFunctionInstance) + sizeof(AOTImportFunc), NULL, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

A little confused why need to plus sizeof(AOTImportFunc)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am considering that this would enable host APIs (defined in wasm_export.h) to create an AOTFunctionInstance from scratch and pass it to the runtime for execution. The runtime would then use the u.func_import field to retrieve some information. However, there might be room for optimization in subsequent pull requests.

wasm_create_function_empty(const WASMModule *module)
{
WASMFunctionInstance *function = runtime_malloc(
sizeof(WASMFunctionInstance) + sizeof(WASMFunctionImport), NULL, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it necessary to allocate extra memory (+ sizeof(WASMFunctionImport))?

@lum1n0us
Copy link
Collaborator Author

In many cases the unlinked import function isn't called and developer can still call other functions.

However, this does not align with the specification definition. I believed the purpose of creating the "instantiation linking" series of pull requests was to align with the specification requirements. Otherwise, our main branch code is functioning quite well.

@wenyongh
Copy link
Contributor

In many cases the unlinked import function isn't called and developer can still call other functions.

However, this does not align with the specification definition. I believed the purpose of creating the "instantiation linking" series of pull requests was to align with the specification requirements. Otherwise, our main branch code is functioning quite well.

It reports the error during the execution time but not instantiation time, it doesn't strictly obey the spec. But sometimes the user experience is more important, in fact, we also do some special handlings in other places. I still think it is good to keep it, it also reports error and it is more friendly to developers.

}

return func_ptr;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

the function body is a little big, is it better to make it no-inlined?

Copy link
Contributor

@wenyongh wenyongh left a comment

Choose a reason for hiding this comment

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

LGTM with minor comments

@lum1n0us lum1n0us merged commit 918b364 into bytecodealliance:dev/instantiate_linking Feb 19, 2025
383 checks passed
@lum1n0us lum1n0us deleted the fix/optimize_aot_func_inst_list branch February 19, 2025 01:31
lum1n0us added a commit to lum1n0us/wasm-micro-runtime that referenced this pull request Feb 19, 2025
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.

2 participants