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

Reimplement how instance exports are stored/loaded #2984

Merged
merged 2 commits into from
Jun 17, 2021

Conversation

alexcrichton
Copy link
Member

This commit internally refactors how instance exports are handled and
fixes two issues. One issue is that when we instantiate an instance we
no longer forcibly load all items from the instance immediately,
deferring insertion of each item into the store data tables to happen
later as necessary. The next issue is that repeated calls to
Caller::get_export would continuously insert items into the store data
tables. While working as intended this was undesirable because it would
continuously push onto a vector that only got deallocated once the
entire store was deallocate. Now it's routed to Instance::get_export
which doesn't have this behavior.

Closes #2916
Closes #2983

This commit internally refactors how instance exports are handled and
fixes two issues. One issue is that when we instantiate an instance we
no longer forcibly load all items from the instance immediately,
deferring insertion of each item into the store data tables to happen
later as necessary. The next issue is that repeated calls to
`Caller::get_export` would continuously insert items into the store data
tables. While working as intended this was undesirable because it would
continuously push onto a vector that only got deallocated once the
entire store was deallocate. Now it's routed to `Instance::get_export`
which doesn't have this behavior.

Closes bytecodealliance#2916
Closes bytecodealliance#2983
@github-actions github-actions bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Jun 14, 2021
@github-actions
Copy link

Subscribe to Label Action

cc @peterhuene

This issue or pull request has been labeled: "wasmtime:api"

Thus the following users have been cc'd because of the following labels:

  • peterhuene: wasmtime:api

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

crates/wasmtime/src/instance.rs Outdated Show resolved Hide resolved
Comment on lines +746 to +748
exports,
types: Arc::clone(self.cur.module.types()),
signatures: Arc::clone(self.cur.module.signatures()),
Copy link
Member

Choose a reason for hiding this comment

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

Kind of unfortunate to add a new malloc call and a couple of atomic inc refs on the instantiation hot path. Did you happen to measure if this has any observable effect on instantiation times?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was actually already happening, although it was even worse. Previously we created an IndexMap with freshly allocated strings for all the names as well. This should perform fewer allocations (only one) as well as be a bit more optimized (it's an array, should be calloc-able).

The atomics I don't think really affect anything, they're on the order of a handful of ns when we shoot for a handful of us for instantiation.

@fitzgen
Copy link
Member

fitzgen commented Jun 14, 2021

I don't really feel familiar enough with this code to give an r+ but those two things jumped out at me when I looked at the PR.

Copy link
Member

@peterhuene peterhuene left a comment

Choose a reason for hiding this comment

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

This looks good to me!

I appreciate the plethora of comments in instantiate_raw too.

@alexcrichton alexcrichton merged commit d8d4bf8 into bytecodealliance:main Jun 17, 2021
@alexcrichton alexcrichton deleted the fix-leak branch June 17, 2021 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasmtime:api Related to the API of the `wasmtime` crate itself
Projects
None yet
3 participants