Skip to content

Commit e9cd131

Browse files
authored
wasmtime: Misc optimizations (bytecodealliance#7102)
* Mark some frequently used methods as `inline` * Seed the preview2 context with the thread_rng, instead of using a syscall
1 parent 7f79a09 commit e9cd131

File tree

5 files changed

+9
-1
lines changed

5 files changed

+9
-1
lines changed

crates/jit/src/instantiate.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ impl CompiledModule {
509509
/// Returns the text section of the ELF image for this compiled module.
510510
///
511511
/// This memory should have the read/execute permissions.
512+
#[inline]
512513
pub fn text(&self) -> &[u8] {
513514
self.code_memory.text()
514515
}
@@ -575,6 +576,7 @@ impl CompiledModule {
575576
///
576577
/// These trampolines are used for native callers (e.g. `Func::wrap`)
577578
/// calling Wasm callees.
579+
#[inline]
578580
pub fn native_to_wasm_trampoline(&self, index: DefinedFuncIndex) -> Option<&[u8]> {
579581
let loc = self.funcs[index].native_to_wasm_trampoline?;
580582
Some(&self.text()[loc.start as usize..][..loc.length as usize])

crates/runtime/src/mmap.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ impl Mmap {
122122
/// # Panics
123123
///
124124
/// Panics of the `range` provided is outside of the limits of this mmap.
125+
#[inline]
125126
pub unsafe fn slice(&self, range: Range<usize>) -> &[u8] {
126127
assert!(range.start <= range.end);
127128
assert!(range.end <= self.len());

crates/runtime/src/mmap_vec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ impl MmapVec {
127127
impl Deref for MmapVec {
128128
type Target = [u8];
129129

130+
#[inline]
130131
fn deref(&self) -> &[u8] {
131132
// SAFETY: this mmap owns its own range of the underlying mmap so it
132133
// should be all good-to-read.

crates/wasi/src/preview2/ctx.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ impl WasiCtxBuilder {
5454
pub fn new() -> Self {
5555
// For the insecure random API, use `SmallRng`, which is fast. It's
5656
// also insecure, but that's the deal here.
57-
let insecure_random = Box::new(cap_rand::rngs::SmallRng::from_entropy());
57+
let insecure_random = Box::new(
58+
cap_rand::rngs::SmallRng::from_rng(cap_rand::thread_rng(cap_rand::ambient_authority()))
59+
.unwrap(),
60+
);
5861

5962
// For the insecure random seed, use a `u128` generated from
6063
// `thread_rng()`, so that it's not guessable from the insecure_random

crates/wasmtime/src/signatures.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl SignatureCollection {
4545
}
4646

4747
/// Gets the shared signature index given a module signature index.
48+
#[inline]
4849
pub fn shared_signature(&self, index: SignatureIndex) -> Option<VMSharedSignatureIndex> {
4950
self.signatures.get(index).copied()
5051
}

0 commit comments

Comments
 (0)