You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Description
This wires up an explicit key cache to replace the implicit one that was
removed in #3051.
~~The default for a key cache is Disabled. A disabled key cache has a
size of 1 pointer and otherwise zero performance overhead.~~
I have removed the Default instance for both KeyCache and DerpProtocol
so you don't accidentally pass the default despite having a cache
available.
We use the lru crate for the cache for now. Please comment if it should
be something else.
Benchmarks have shown that conversion from a [u8;32] to a VerifyingKey
is relatively cheap, so the purpose of the cache is solely to validate
incoming public keys.
We add a Borrow instance to PublicKey so we can use it as a cache key.
Some performance measurements:
```
Benchmarking validate valid ed25519 key: 3.7674 µs
Benchmarking validate invalid ed25519 key: 3.6637 µs
Benchmarking validate valid iroh ed25519 key: 67.089 ns
Benchmarking validate invalid iroh ed25519 key: 64.004 ns
```
So just from validating incoming keys, without cache you would be
limited to ~250 000 msgs/s per thread. At a message size of 1KiB that
would be 250MB/s, which is not great.
With the cache deserialization can do 14 000 000 msgs/s, which means
that this is no longer a bottleneck.
## Breaking Changes
- RelayConfig has new public field key_cache_capacity
## Notes & open questions
- Size of the cache
- source_and_box has a PublicKey::try_from. Is that perf critical?
## Change checklist
- [ ] Self-review.
- [ ] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [ ] Tests if relevant.
- [ ] All breaking changes documented.
---------
Co-authored-by: dignifiedquire <me@dignifiedquire.com>
0 commit comments