bkolobara opened issue #2992:
The RFC 11 mentions an addition of
sub_linker
.Note that a new API is also provided,
sub_linker()
. This method allows creating a "child" linker which inherits all of the previous values set by the parent but also allows defining new values in the returned value for instantiation.It was not added yet, but it would be nice to have for my use case. I define a lot of host functions in the
Linker
, but then for eachStore
add a different module as an import. This immediately "poisons" the Linker with a particularStore
and I need to re-add all the host functions again to a newLinker
for otherStore
s.Maybe, just having
Clone
on theLinker
would be enough here.
alexcrichton commented on issue #2992:
Oh wow I completely forgot that
Clone
was a possibility here! I added that in https://github.com/bytecodealliance/wasmtime/pull/2993 because it seems pretty reasonable to me. The runtime of that will be slower than thesub_linker
idea because things need cloning, but is that ok for your use case?
bkolobara commented on issue #2992:
I always assumed that the most expensive part of adding host functions was the trampoline creation, and this would be faster with cloning, instead of recreating
Linker
s?The previous api
Config::wrap_host_func
was a perfect fit for my use case, but I think thatClone
should also be fine.Thanks for the super fast response!
alexcrichton commented on issue #2992:
Whether or not it's fast sort of depends on your use case and which part you're stressing. Want to try out the
Clone
impl though and see if it works for you?
bkolobara commented on issue #2992:
I ran some benchmarks with the
Clone
implementation. It takes around +35% more time per request in our current system, compared to an implementation that doesn't clone theLinker
.This is still significantly better than what we do right now, re-creating the Linker from scratch (15x slower), because we need to use different
Stores
with each.The only issues is that it keeps getting worse if I artificially increase the number of host functions (with 200 the throughput decreases 50%). I expect the number of host functions to further grow in our system.
I would still love to see a
sub_linker()
API in the future, that doesn't decrease performance with more host functions.
Last updated: Nov 22 2024 at 17:03 UTC