Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Better allocator for Wasm #300

@gavofyork

Description

@gavofyork

We currently use a Linear Allocator. It's very inefficient and means we need ~128 x 64KB pages to validate a block with a 350kb transaction in it. Switch this for a Buddy allocator or Slab allocator.

Furthermore, sr-io::storage was recently pessimised through adding a needless memcpy in to_vec. The code should be reverted thus:

/// Get `key` from storage and return a `Vec`, empty if there's a problem.
pub fn storage(key: &[u8]) -> Option<Vec<u8>> {
	let mut length: u32 = 0;
	unsafe {
		let ptr = ext_get_allocated_storage(key.as_ptr(), key.len() as u32, &mut length);
		if length == u32::max_value() {
			None
		} else {
			Some(<Vec<u8>>::from_raw_parts(ptr, length as usize))
		}
	}
}

To ensure this code doesn't result in UB on the part of Vec, ext_get_allocated_storage should ensure that the pointer is aligned according to u8 allocations on the unknown-unknown-webassembly platform (almost certainly 4 byte). This is won't be necessary as long as the Heap implementation ensures all allocations are on such a boundary.

Metadata

Metadata

Labels

I9-optimisationAn enhancement to provide better overall performance in terms of time-to-completion for a task.U2-some_time_soonIssue is worth doing soon.Z2-mediumCan be fixed by a coder with good Rust knowledge but little knowledge of the codebase.Z6-mentorAn easy task where a mentor is available. Please indicate in the issue who the mentor could be.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions