-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Reuse VM memory across executions #1888
Merged
Merged
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
81dc78a
Reuse VM memory across executions
Dentosal 42105ce
Add changelog entry
Dentosal e14cf0b
Merge branch 'master' into dento/reuse-vm-memory
Dentosal 5caec42
Switch to a unified pool instead of per-thread one
Dentosal 6340785
Move VmPool to fuel-vm, use it for predicates as well
Dentosal 22fa926
Cleanup
Dentosal 8c276e9
Cleanup
Dentosal 0b11719
Fix benches
Dentosal 4c6f29b
Add changes from the latest fuel-vm side update
Dentosal 22f3ba4
Match fuel-vm changes
Dentosal 4f9340c
Merge branch 'master' into dento/reuse-vm-memory
Dentosal 57d2049
cargo sort
Dentosal 0e41a28
Merge branch 'refs/heads/master' into dento/reuse-vm-memory
xgreenx a762483
Use `fuel-vm 0.51.0`
xgreenx 131a91e
Merge branch 'master' into dento/reuse-vm-memory
xgreenx 98c7495
Make clippy happy
xgreenx 395077b
Fix CI
xgreenx 36fa8be
Fix CI
xgreenx 3baea26
Fix CI
xgreenx b13578f
Fixed VM initialization benchmark
xgreenx eb65aba
Merge branch 'master' into dento/reuse-vm-memory
xgreenx 5196bab
Use release 0.51
xgreenx 2e4bc5b
Merge remote-tracking branch 'origin/dento/reuse-vm-memory' into dent…
xgreenx c2034bb
Make clippy happy
xgreenx ec2a65b
Fixed becnhmark for aloc opcode
xgreenx fc15915
Fixed becnhmark for aloc opcode
xgreenx 6000f11
Not include cloning of memory into the benchamrk results
xgreenx 56915e7
Return back old benchmark
xgreenx 8680666
Merge branch 'master' into dento/reuse-vm-memory
xgreenx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
#![deny(clippy::arithmetic_side_effects)] | ||
#![deny(clippy::cast_possible_truncation)] | ||
#![deny(unused_crate_dependencies)] | ||
#![deny(warnings)] | ||
// #![deny(warnings)] | ||
|
||
pub mod executor; | ||
pub mod ports; | ||
pub mod refs; | ||
mod vm_pool; | ||
|
||
#[cfg(test)] | ||
fuel_core_trace::enable_tracing!(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use std::cell::RefCell; | ||
|
||
use fuel_core_types::fuel_vm::interpreter::Memory; | ||
|
||
thread_local! { | ||
static POOL: RefCell<Vec<Memory>> = RefCell::new(Vec::new()); | ||
} | ||
|
||
/// Gets a new VM memory instance from the pool. | ||
pub(crate) fn get_vm_memory() -> Memory { | ||
POOL.with(|pool| { | ||
let mut pool = pool.borrow_mut(); | ||
pool.pop().unwrap_or_else(Memory::new) | ||
}) | ||
} | ||
|
||
/// Recycles a VM memory instance back into the pool. | ||
pub(crate) fn recycle_vm_memory(mut mem: Memory) { | ||
POOL.with(|pool| { | ||
mem.reset(); | ||
let mut pool = pool.borrow_mut(); | ||
pool.push(mem); | ||
}) | ||
} | ||
|
||
#[test] | ||
fn test_vm_pool() { | ||
let mut mem = get_vm_memory(); | ||
mem.grow_stack(1024).expect("Unable to grow stack"); | ||
mem.write_bytes_noownerchecks(0, [1, 2, 3, 4]) | ||
.expect("Unable to write stack"); | ||
let ptr1 = mem.stack_raw() as *const _ as *const u8 as usize; | ||
recycle_vm_memory(mem); | ||
|
||
// Make sure we get the same memory allocation back | ||
let mem = get_vm_memory(); | ||
let ptr2 = mem.stack_raw() as *const _ as *const u8 as usize; | ||
assert_eq!(ptr1, ptr2); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably have some kind constraint on the max number of items allowed in each pool? Otherwise it should wait if there are none available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We didn't do this earlier, and I don't see why it would make sense to track the items here, instead of just limiting concurrency of the executor itself. That said, keeping a pool per thread is by itself problematic and not useful, as:
So I' changed the code to not keep separate pools in 5caec42