Skip to content

fix: avoid creating too many externrefs#759

Merged
zshipko merged 3 commits intomainfrom
fix-host-context
Aug 30, 2024
Merged

fix: avoid creating too many externrefs#759
zshipko merged 3 commits intomainfrom
fix-host-context

Conversation

@zshipko
Copy link
Copy Markdown
Contributor

@zshipko zshipko commented Aug 29, 2024

Updates plugins to allocate a single ExternRef for the host context up front, to avoid running into the failed to allocate externref error from Wasmtime

@zshipko zshipko requested a review from chrisdickinson August 29, 2024 23:47
Copy link
Copy Markdown
Contributor

@chrisdickinson chrisdickinson left a 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!

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(())
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

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
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

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.

@zshipko zshipko merged commit d2a3699 into main Aug 30, 2024
@zshipko zshipko deleted the fix-host-context branch August 30, 2024 00:24
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