-
Notifications
You must be signed in to change notification settings - Fork 106
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
Add options to specify cache type #338
base: master
Are you sure you want to change the base?
Add options to specify cache type #338
Conversation
@kevinmehall Umm the test failed because it was running under |
A couple thoughts / concerns with this:
I wouldn't mind just skipping the no_std tests when the |
Maybe we will need to define the cache behavior. I think we should first try to insert the entry, and if not we should execute the rest of the production rule as usual.
I theorize the following situation: because hash-based containers are based on cost amortization (that means the algorithmic cost to a certain operation would be asymptomatically closer to the big-O once it go large), it will struggle a lot on if you have little to no entries but big batches of repeated stuff. This is because the smaller the hash structure, the more the chance to require hash map expansion and rehashing. Given we have a large amount of recursive parsing calls in a PEG parser, so I suggest using a binary tree-based map would yield a nice improvement on the expected performance/throughput over a hash one, because the behavior would be much more stable and deterministic since a self-balancing binary tree should take O(log n) time for any operations (hash map can achieve O(1) only if amortized, so it can be closer to O(n) for the first 512 entries-ish idk). ...Well on the other hand, also theoretically, O(log n) is by definition slower than O(1), so maybe a benchmark is still needed to test it through. We could also test if we FNV, SipHash, Farmhash, compared with B+ tree, Scapegoat tree or even a naive index map (that is just a linear array and you do linear search) could make a difference.
It's for completeness. I use peg to parse serial console command and sometimes ACPI bytecode. Although both of them often work fine without cache so far, but they are for embedded use, and I can't risk to use a hash map on deterministic ground. |
I also wanted to test how well it work with the cache that does cache replacement, i.e. LRU, TinyLFU and so on. |
Part 3 of #294 series, and this PR focuses on letting the user to specify their own cache type under context such as
no_std
or when the user needs to explicitly state the kind of cache type they wanted to use. This means users can now supply LinearMap in heapless - Rust (docs.rs), SgMap in scapegoat - Rust (docs.rs), or even Simsys/fchashmap: A fixed capacity no_std hashmap (github.com).As I tried before I want to consolidate the cache interface into one facade trait stated here but I quickly found that I would have to use a
Box
to wrap the dynamic trait -- which is not acceptable inno_std
environment. This means we have to resort to using "duck typing" that we have to specify concrete type in the cache type definition. The cache type must follow the following "trait protocol":And the type must implement
Default
This PR is based on #336 and #337 as a prerequisite.