Skip to content

Commit

Permalink
Merge pull request #24 from tweedegolf/key-cache
Browse files Browse the repository at this point in the history
Key cache
  • Loading branch information
diondokter authored Feb 11, 2024
2 parents d549965 + e5aa3cd commit 2885479
Show file tree
Hide file tree
Showing 14 changed files with 1,513 additions and 907 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

(DD-MM-YY)

## Unreleased

- *Breaking:* Storage item key must now also be clone
- Added KeyPointerCache which significantly helps out the map

## 0.8.1 07-02-24

- Added new PagePointerCache that caches more than the PageStateCache. See the readme for more details.
Expand Down
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ Instead, we can optionally store some state in ram.

These numbers are taken from the test cases in the cache module:

| Name | RAM bytes | Map # flash reads | Map flash bytes read | Queue # flash reads | Queue flash bytes read |
| ---------------: | ------------: | ----------------: | -------------------: | ------------------: | ---------------------: |
| NoCache | 0 | 100% | 100% | 100% | 100% |
| PageStateCache | 1 * num pages | 77% | 97% | 51% | 90% |
| PagePointerCache | 9 * num pages | 69% | 89% | 35% | 61% |
| Name | RAM bytes | Map # flash reads | Map flash bytes read | Queue # flash reads | Queue flash bytes read |
| ---------------: | -------------------------------------------: | ----------------: | -------------------: | ------------------: | ---------------------: |
| NoCache | 0 | 100% | 100% | 100% | 100% |
| PageStateCache | 1 * num pages | 77% | 97% | 51% | 90% |
| PagePointerCache | 9 * num pages | 69% | 89% | 35% | 61% |
| KeyPointerCache | 9 * num pages + (sizeof(KEY) + 4) * num keys | 6.5% | 8.5% | - | - |

#### Takeaways

Expand All @@ -87,6 +88,10 @@ These numbers are taken from the test cases in the cache module:
- PagePointerCache
- Very efficient for the queue
- Minimum cache level that makes a dent in the map
- KeyPointerCache
- Awesome savings!
- Numbers are less good if there are more keys than the cache can store
- Same as PagePointerCache when used for queue

## Inner workings

Expand Down
6 changes: 4 additions & 2 deletions fuzz/fuzz_targets/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use libfuzzer_sys::arbitrary::Arbitrary;
use libfuzzer_sys::fuzz_target;
use rand::SeedableRng;
use sequential_storage::{
cache::{CacheImpl, NoCache, PagePointerCache, PageStateCache},
cache::{KeyCacheImpl, KeyPointerCache, NoCache, PagePointerCache, PageStateCache},
map::{MapError, StorageItem},
mock_flash::{MockFlashBase, MockFlashError, WriteCountCheck},
};
Expand All @@ -19,6 +19,7 @@ fuzz_target!(|data: Input| match data.cache_type {
CacheType::NoCache => fuzz(data, NoCache::new()),
CacheType::PageStateCache => fuzz(data, PageStateCache::<PAGES>::new()),
CacheType::PagePointerCache => fuzz(data, PagePointerCache::<PAGES>::new()),
CacheType::KeyPointerCache => fuzz(data, KeyPointerCache::<PAGES, u8, 64>::new()),
});

#[derive(Arbitrary, Debug, Clone)]
Expand Down Expand Up @@ -101,9 +102,10 @@ enum CacheType {
NoCache,
PageStateCache,
PagePointerCache,
KeyPointerCache,
}

fn fuzz(ops: Input, mut cache: impl CacheImpl) {
fn fuzz(ops: Input, mut cache: impl KeyCacheImpl<u8>) {
let mut flash = MockFlashBase::<PAGES, WORD_SIZE, WORDS_PER_PAGE>::new(
WriteCountCheck::OnceOnly,
Some(ops.fuel as u32),
Expand Down
Loading

0 comments on commit 2885479

Please sign in to comment.