Many performance and memory optimizations

- Avoiding a memory copy on all socket reads and writes using a new `copy_from_slice` instead
- File openers no longer box the implementation avoiding a memory allocation on all file access
- Polling sockets rather than using an async function which significantly reduces locking contention and removes an box operation
- Futex now uses wakers rather than broadcasts which makes them more efficient and durable
- Converted many async functions into sync functions in vnet
- Sleeping no longer allocates memory
- Avoiding a number of WasiEnv clones which was impacting performance and memory efficiency
This commit is contained in:
Johnathan Sharratt
2023-02-05 10:16:41 +11:00
committed by Christoph Herzog
parent 7f8c0858b3
commit 26d4a6a0de
71 changed files with 2025 additions and 2123 deletions

View File

@@ -311,6 +311,17 @@ impl<'a, T: ValueType> WasmSlice<'a, T> {
self.buffer.write(self.offset, bytes)
}
/// Reads this `WasmSlice` into a `slice`.
#[inline]
pub fn read_to_slice<'b>(
self,
buf: &'b mut [MaybeUninit<u8>],
) -> Result<usize, MemoryAccessError> {
let len = self.len.try_into().expect("WasmSlice length overflow");
self.buffer.read_uninit(self.offset, buf)?;
Ok(len)
}
/// Reads this `WasmSlice` into a `Vec`.
#[inline]
pub fn read_to_vec(self) -> Result<Vec<T>, MemoryAccessError> {

View File

@@ -313,6 +313,17 @@ impl<'a, T: ValueType> WasmSlice<'a, T> {
self.buffer.write(self.offset, bytes)
}
/// Reads this `WasmSlice` into a `slice`.
#[inline]
pub fn copy_to_slice<'b>(
self,
buf: &'b mut [MaybeUninit<u8>],
) -> Result<usize, MemoryAccessError> {
let len = self.len.try_into().expect("WasmSlice length overflow");
self.buffer.read_uninit(self.offset, buf)?;
Ok(len)
}
/// Reads this `WasmSlice` into a `Vec`.
#[inline]
pub fn read_to_vec(self) -> Result<Vec<T>, MemoryAccessError> {