Skip to content
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

Key cache #24

Merged
merged 5 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading