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

Use rkyv for JIT Engine #2250

Merged
merged 24 commits into from
Apr 30, 2021
Merged

Use rkyv for JIT Engine #2250

merged 24 commits into from
Apr 30, 2021

Conversation

syrusakbary
Copy link
Member

@syrusakbary syrusakbary commented Apr 22, 2021

Since we are going to switch serialization methods, the new one doesn’t have a slowdown if we read the data directly.

Thus, we can always operate with processed frame infos rather than creating a lazy structure that will be deserialized when needed.

Try it:

git clone https://github.com/wasmerio/wasmer.git -b universal-compiled-info
cd wasmer
make build-wasmer
./target/release/wasmer run lib/c-api/tests/assets/qjs.wasm --disable-cache -- -h

Since we are going to switch serialization methods, the new one doesn’t have a slowdown if we read the data directly. Thus, we can always operate with processed frame infos
@syrusakbary
Copy link
Member Author

bors try

bors bot added a commit that referenced this pull request Apr 22, 2021
@bors
Copy link
Contributor

bors bot commented Apr 22, 2021

try

Build failed:

@syrusakbary
Copy link
Member Author

bors try

bors bot added a commit that referenced this pull request Apr 29, 2021
@bors
Copy link
Contributor

bors bot commented Apr 29, 2021

try

Build failed:

lib/engine-jit/src/artifact.rs Outdated Show resolved Hide resolved
lib/engine-jit/src/artifact.rs Outdated Show resolved Hide resolved
lib/engine-jit/src/artifact.rs Outdated Show resolved Hide resolved
lib/engine-jit/src/artifact.rs Outdated Show resolved Hide resolved
lib/engine-jit/src/artifact.rs Outdated Show resolved Hide resolved
lib/engine-jit/src/artifact.rs Outdated Show resolved Hide resolved
lib/types/src/archives.rs Outdated Show resolved Hide resolved
lib/types/src/lib.rs Outdated Show resolved Hide resolved
lib/engine-jit/src/artifact.rs Outdated Show resolved Hide resolved
lib/engine-jit/src/artifact.rs Show resolved Hide resolved
lib/engine-jit/src/artifact.rs Outdated Show resolved Hide resolved
lib/engine-jit/src/artifact.rs Show resolved Hide resolved
lib/engine-jit/src/artifact.rs Outdated Show resolved Hide resolved
Ok(serialized)
}
}

pub fn append_data(mut prev_data: Vec<u8>, data: &[u8], align: u64) -> (Vec<u8>, u64) {
let align = align as usize;
Copy link
Contributor

Choose a reason for hiding this comment

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

There's not much reason to use u64 over usize in this function, if we're talking about offsets into an array, usize is the most natural type

Copy link
Member Author

Choose a reason for hiding this comment

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

u64 will shield us in 32 bit systems?

Copy link
Contributor

Choose a reason for hiding this comment

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

Because it's referring to an offset in memory it doesn't matter. On a 32bit system you only have 32 bits of addressable memory. A usize is defined to be the size big enough to cover all addressable memory, so when dealing with offsets it's a natural size. It makes sense to cast it to a u64 before writing it if you want it to take up a constant 8 bytes on all platforms, but when dealing with pointers / offsets, a usize will always be good enough and do the right thing on all platforms.

lib/engine-jit/src/serialize.rs Show resolved Hide resolved
lib/engine/src/serialize.rs Show resolved Hide resolved
lib/types/src/archives.rs Outdated Show resolved Hide resolved
lib/types/src/lib.rs Outdated Show resolved Hide resolved
lib/vm/src/lib.rs Show resolved Hide resolved
@syrusakbary syrusakbary changed the title Improved frame_info to be always processed Use rkyv for JIT Engine Apr 29, 2021
@djkoloski
Copy link

The blocking bug has been fixed as of 0.6.1. rkyv issue: rkyv/rkyv#116

@syrusakbary
Copy link
Member Author

Thanks for the super quick fix @djkoloski!

@syrusakbary
Copy link
Member Author

bors try

bors bot added a commit that referenced this pull request Apr 30, 2021
@bors
Copy link
Contributor

bors bot commented Apr 30, 2021

try

Build failed:

Copy link
Contributor

@Hywan Hywan left a comment

Choose a reason for hiding this comment

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

The code looks good! I've a question about the required vs. optinal feature enable-rkyv. How do you want to deal with that? serde has always been optional, so I would expect rkyv to be optional too. Inside wasmer-cli, we can force rkyv though, as it provides much better performance.

lib/cli/src/commands/run.rs Outdated Show resolved Hide resolved
lib/engine-jit/Cargo.toml Show resolved Hide resolved
lib/engine-jit/Cargo.toml Show resolved Hide resolved
@syrusakbary
Copy link
Member Author

I would expect rkyv to be optional too. Inside wasmer-cli, we can force rkyv though, as it provides much better performance

Engines serialization mechanisms should be fixed. If you compile with the wasmer-cli you can expect an embedded user of Wasmer can run Module::deserialize_from_file(...) on that exact file. Because of that serialization methods for an engine should be fixed and not movable.

Copy link
Contributor

@MarkMcCaskey MarkMcCaskey left a comment

Choose a reason for hiding this comment

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

Looks good! Just a few minor things, but glad things are working

lib/engine-jit/src/artifact.rs Show resolved Hide resolved
lib/engine-jit/src/artifact.rs Outdated Show resolved Hide resolved
lib/engine-jit/src/artifact.rs Outdated Show resolved Hide resolved
lib/engine-jit/src/artifact.rs Outdated Show resolved Hide resolved
lib/engine-jit/src/artifact.rs Outdated Show resolved Hide resolved
Ok(serialized)
}
}

pub fn append_data(mut prev_data: Vec<u8>, data: &[u8], align: u64) -> (Vec<u8>, u64) {
let align = align as usize;
Copy link
Contributor

Choose a reason for hiding this comment

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

Because it's referring to an offset in memory it doesn't matter. On a 32bit system you only have 32 bits of addressable memory. A usize is defined to be the size big enough to cover all addressable memory, so when dealing with offsets it's a natural size. It makes sense to cast it to a u64 before writing it if you want it to take up a constant 8 bytes on all platforms, but when dealing with pointers / offsets, a usize will always be good enough and do the right thing on all platforms.

lib/engine-jit/src/artifact.rs Outdated Show resolved Hide resolved
lib/engine-jit/src/serialize.rs Outdated Show resolved Hide resolved
lib/vm/src/libcalls.rs Show resolved Hide resolved
Copy link
Contributor

@MarkMcCaskey MarkMcCaskey left a comment

Choose a reason for hiding this comment

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

Looks good overall, I just noticed 2 quick issues

lib/engine-jit/src/artifact.rs Show resolved Hide resolved
lib/engine-jit/src/artifact.rs Show resolved Hide resolved
lib/engine-jit/src/serialize.rs Show resolved Hide resolved
@syrusakbary
Copy link
Member Author

bors r+

@bors
Copy link
Contributor

bors bot commented Apr 30, 2021

@bors bors bot merged commit 8012f3f into master Apr 30, 2021
@bors bors bot deleted the universal-compiled-info branch April 30, 2021 20:06
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.

5 participants