-
Notifications
You must be signed in to change notification settings - Fork 824
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
Use a buffer abstraction for files in virtual_fs::mem_fs
and Module::deserialize()
#3875
Comments
I abstracted the |
virtual_fs::mem_fs
virtual_fs::mem_fs
and Module::deserialize()
@john-sharratt also suggested using something like this when deserializing modules on Slack (#3882). |
Motivation
The
virtual_fs::mem_fs::file::ReadOnlyFile
struct currently uses aCow<'static, [u8]>
for its backing bytes.wasmer/lib/virtual-fs/src/mem_fs/file.rs
Lines 1341 to 1345 in fbe784a
On its own this is fine, however, we uses a lot of memory-mapped files in order to keep RAM usage down, and to deal with the fact that any slices coming from a memory-mapped file will have a non-
'static
lifetime, wetransmute()
the lifetime away and are "really careful" that theMmap
object they came from will outlive thevirtual_fs::mem_fs::FileSystem
object they are stored in.wasmer/lib/wasi/src/state/env.rs
Lines 914 to 926 in fbe784a
Possible Solutions
The simplest solution is to take the
&[u8]
we get from aBinaryPackageCommand
and create a copy of it withinto_owned()
. That's the approach originally taken in #3777, but it was reverted in 02b8e42 after comments from @theduke and @john-sharratt (#3777 (comment), #3777 (comment)).A smarter solution would be to introduce something that is either backed by a memory-mapped file or an in-memory object. That's the approach taken by
SharedBytes
in thewebc
crate.Alternatively, we could add an extra level of indirection and use something like
Arc<dyn AsRef<[u8]>>
(or a custom trait). That way we'd be able to useArc<[u8]>
orArc<MmapBackedSlice>
, whereMmapBackedSlice
does thatRepr::as_slice()
trick.The text was updated successfully, but these errors were encountered: