Skip to content

Improve Wasm module linking facilities#2

Merged
orsinium merged 12 commits intofirefly-zero:mainfrom
Robbepop:rf-use-linker-new
Feb 6, 2026
Merged

Improve Wasm module linking facilities#2
orsinium merged 12 commits intofirefly-zero:mainfrom
Robbepop:rf-use-linker-new

Conversation

@Robbepop
Copy link
Contributor

@Robbepop Robbepop commented Jan 25, 2026

This PR replaces the current usage of wasmi::Linker with the more low-level and efficient Instance::new.

The new linking facilities act lazily and only populate the externals buffer with what the module to be instantiated actually needs. In contrast the old linking facilities act eagerly and populate all available host functions onto the linker even if only a tiny fraction of them are in use.

This should improve performance and may even improve binary artifact size.

Caution: I was not able to locate end-to-end tests so I could not really test the changes. The old test is also no longer applicable to the new API. A new API that tests all paths would require a Wasm module that imports all available host functions.

This PR is best reviewed commit by commit.

A follow-up to further improve performance might be to re-use the externals buffer for multiple instantiations if that's a common use case.

@Robbepop Robbepop changed the title Improve linking facilities Improve Wasm module linking facilities Jan 25, 2026
@orsinium
Copy link
Member

orsinium commented Feb 6, 2026

Thank you! I forgot to set the Watch settings for the repo and almost missed the PR. Damn, it's a lot. I'll do my best.

@orsinium orsinium self-requested a review February 6, 2026 17:51
@Robbepop
Copy link
Contributor Author

Robbepop commented Feb 6, 2026

Thank you! I forgot to set the Watch settings for the repo and almost missed the PR. Damn, it's a lot. I'll do my best.

Hey no problem, I know that you are very busy with this project. Happy if I can help a bit with this PR. :)

I am going to resolve conflicts now. From what I see you added 2 new sudo host functions which this PR has to mirror.

        linker.func_wrap("sudo", "list_files", sudo::list_files)?;
        linker.func_wrap("sudo", "list_files_buf_size", sudo::list_files_buf_size)?;

Also I just noticed that we can use Vec::reserve since we know the exact number of module imports thus decreasing pressure on the heap allocator even further with this PR.

@Robbepop
Copy link
Contributor Author

Robbepop commented Feb 6, 2026

Great improvements. Love the signature simplifications! :)

@orsinium
Copy link
Member

orsinium commented Feb 6, 2026

Thank you! I just try to avoid macros, too magical for me :) I'll simplify it a bit more after merging. Thank you for your help :)

@orsinium orsinium merged commit e973568 into firefly-zero:main Feb 6, 2026
@Robbepop
Copy link
Contributor Author

Robbepop commented Feb 6, 2026

Thank you! I just try to avoid macros, too magical for me :) I'll simplify it a bit more after merging. Thank you for your help :)

Haha, I can understand the "too magic" macros. :D Glad I was able to help a tiny bit.

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