-
Notifications
You must be signed in to change notification settings - Fork 148
fix: avoid creating too many externrefs #759
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oof, that's a tricky one! I left one comment to address – zeroing out self.host_context
when we don't receive a host context – but otherwise I think this LGTM!
@@ -366,7 +368,7 @@ fn test_call_with_host_context() { | |||
[PTR], | |||
UserData::default(), | |||
|current_plugin, _val, ret, _user_data: UserData<()>| { | |||
let foo = current_plugin.host_context::<Foo>()?; | |||
let foo = current_plugin.host_context::<Foo>()?.clone(); | |||
let hnd = current_plugin.memory_new(foo.message)?; | |||
ret[0] = current_plugin.memory_to_val(hnd); | |||
Ok(()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The invariant that's on my mind: if I call_with_host_context(host context = A)
and then call()
, will host functions invoked by the second call
see A
as their context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The host context should be reset before the next call (see the comment below for the link)
} | ||
Some(self.host_context.clone()) | ||
} else { | ||
None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we may want to zero out self.host_context
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made it so we're zeroing out the host context after each call: https://github.com/extism/extism/pull/759/files/be744b5ea7df5c1a6f3d5accb28324c811a71e73#diff-fc3b26932af6a72d6a908c3d72663d22045526b2c46c6777aadeb7852d1137d4R816 - but am open to moving it up to here if you think that makes more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, perfect! That makes sense.
Updates plugins to allocate a single
ExternRef
for the host context up front, to avoid running into thefailed to allocate externref
error from Wasmtime