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

Question re. dynamic linking #665

Open
Shillaker opened this issue Aug 2, 2022 · 0 comments
Open

Question re. dynamic linking #665

Shillaker opened this issue Aug 2, 2022 · 0 comments

Comments

@Shillaker
Copy link
Collaborator

Shillaker commented Aug 2, 2022

I received this over email:

I have a question regarding Faasm's dynamic linking implementation.

From what I understand, to actually run a wasm module, you need to compile it and then load the compiled code into memory.

In the case of dynamic linking implemented in Faasm, is it also compiled before actually running? Is there any other like AOT is used to reduce the load time?

Regarding memory footprint, if the wasm needs to be compiled again, that means the wasm module will always have their own compiled copy of the dynamic linked wasm library module. Is it true that actually we cannot use this dynamic linking to reduce the runtime memory footprint of the runtime instances?

Dynamic linking in Faasm works as follows:

  • All dynamically linked modules in Faasm are compiled to wasm, and we run AOT machine code generation on them too (just like the functions themselves)
  • When another module calls dlopen, we find the compiled wasm and machine code, and load them using the same mechanism normally used to load a function
  • We then link the dynamically loaded module with the main function module according to the approach proposed in the wasm tool-conventions. This happens in the WAVMWasmModule.cpp file

The simplest example of dynamic linking is in the demo function demo/dynlink, which is compiled from the fake task here.

If a given module is dynamically linked by multiple functions on the same node, it will only be loaded once and cached by Faasm. Therefore, it would indeed be more memory efficient for modules to reuse code via dynamic linking. However, whether this would be significant depends on the size of the wasm memory, for example, if my application is using multiple GB of memory to hold some data, it won't be that significant to save a few kBs by reusing a dynamically linked module.

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

No branches or pull requests

1 participant