-
Notifications
You must be signed in to change notification settings - Fork 41
pem: avoid some allocations #83
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
69f9509 to
e88375b
Compare
Haven't reviewed the contents of the diff yet, but speaking strictly about the effects it has in The baseline I shared the other day was rustls-ffi 0.15 and curl 8.14.1:
Here's the same test but
A quick back-of-the-envelope check ( |
|
I'm a little enticed to build a parser type that can hold on to the temporary buffers across PEM files for use in rustls-native-certs, but maybe that's overkill? |
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.
nice!
I think for rustls-native-certs with its current API, the best we could do is one allocation per certificate. So another option would be making the base64 decoder in this crate operate in-place, meaning that the temporary buffer for PEM decoding is the one returned in each |
What trade-offs are you thinking about? |
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.
Really nice 🤩
Thinking about this more, we're already doing ~1 allocation per certificate in the scenario under test. Opportunities for further improvement:
Feels like none of these are as low-hanging as the stuff I did here, so I'm not convinced it's worth chasing them down now. |


+57 lines so it's not free, but IMO the complexity isn't much worse, by virtue of using more descriptive types/functions and pushing complexity to the edges.
What do you think?
@cpu want to run this through your test setup?