Skip to content

Commit

Permalink
Merge pull request #700 from CosmWasm/pinned-memory-cache
Browse files Browse the repository at this point in the history
Pinned memory cache
  • Loading branch information
webmaster128 authored Jan 12, 2021
2 parents e69ac7e + daf3dac commit 18dfdbf
Show file tree
Hide file tree
Showing 13 changed files with 333 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

**cosmwasm-vm**

- Add PinnedMemoryCache. (#696)
- Avoid serialization of Modules in `InMemoryCache`, for performance. (#697)

Also, remove `memory_limit` from `InstanceOptions`, and define it instead at
Expand Down
27 changes: 24 additions & 3 deletions packages/vm/benches/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn bench_instance(c: &mut Criterion) {
..DEFAULT_INSTANCE_OPTIONS
};
let mut instance =
Instance::from_code(CONTRACT, backend, much_gas, DEFAULT_MEMORY_LIMIT).unwrap();
Instance::from_code(CONTRACT, backend, much_gas, Some(DEFAULT_MEMORY_LIMIT)).unwrap();

b.iter(|| {
let info = mock_info("creator", &coins(1000, "earth"));
Expand All @@ -60,7 +60,7 @@ fn bench_instance(c: &mut Criterion) {
..DEFAULT_INSTANCE_OPTIONS
};
let mut instance =
Instance::from_code(CONTRACT, backend, much_gas, DEFAULT_MEMORY_LIMIT).unwrap();
Instance::from_code(CONTRACT, backend, much_gas, Some(DEFAULT_MEMORY_LIMIT)).unwrap();

let info = mock_info("creator", &coins(1000, "earth"));
let msg = br#"{"verifier": "verifies", "beneficiary": "benefits"}"#;
Expand Down Expand Up @@ -115,6 +115,7 @@ fn bench_cache(c: &mut Criterion) {
let _ = cache
.get_instance(&checksum, mock_backend(&[]), DEFAULT_INSTANCE_OPTIONS)
.unwrap();
assert_eq!(cache.stats().hits_pinned_memory_cache, 0);
assert_eq!(cache.stats().hits_memory_cache, 0);
assert!(cache.stats().hits_fs_cache >= 1);
assert_eq!(cache.stats().misses, 0);
Expand All @@ -135,8 +136,28 @@ fn bench_cache(c: &mut Criterion) {
let _ = cache
.get_instance(&checksum, backend, DEFAULT_INSTANCE_OPTIONS)
.unwrap();
assert_eq!(cache.stats().hits_fs_cache, 1);
assert_eq!(cache.stats().hits_pinned_memory_cache, 0);
assert!(cache.stats().hits_memory_cache >= 1);
assert_eq!(cache.stats().hits_fs_cache, 1);
assert_eq!(cache.stats().misses, 0);
});
});

group.bench_function("instantiate from pinned memory", |b| {
let checksum = Checksum::generate(CONTRACT);
let mut cache: Cache<MockApi, MockStorage, MockQuerier> =
unsafe { Cache::new(options.clone()).unwrap() };
// Load into pinned memory
cache.pin(&checksum).unwrap();

b.iter(|| {
let backend = mock_backend(&[]);
let _ = cache
.get_instance(&checksum, backend, DEFAULT_INSTANCE_OPTIONS)
.unwrap();
assert_eq!(cache.stats().hits_memory_cache, 0);
assert!(cache.stats().hits_pinned_memory_cache >= 1);
assert_eq!(cache.stats().hits_fs_cache, 1);
assert_eq!(cache.stats().misses, 0);
});
});
Expand Down
Loading

0 comments on commit 18dfdbf

Please sign in to comment.