-
Notifications
You must be signed in to change notification settings - Fork 297
feat: Make fmt_short return an impl Display so we can avoid an allocation. #3460
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
Conversation
Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh/pr/3460/docs/iroh/ Last updated: 2025-09-22T09:28:03Z |
iroh-base/src/key.rs
Outdated
pub const LENGTH: usize = ed25519_dalek::PUBLIC_KEY_LENGTH; | ||
} | ||
|
||
struct PublicKeyShort(PublicKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old code used space for 10 bytes on the heap. This version uses 32 bytes on the stack?
I think it's a great idea to try and get rid of the heap allocation. But maybe you can give PublicKeyShort
only the 5 bytes needed for the display?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you could do that easily. PublicKeyShort is not part of the public API, so you can optimize it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think the optimisation of only copying 5 bytes is worth it here.
Description
Currently, fmt_short allocates a String. It is used quite a few times in trace! statements. This makes it not allocate.
Not sure if it is worth it.
Breaking Changes
Notes & open questions
Change checklist
quic-rpc
iroh-gossip
iroh-blobs
dumbpipe
sendme