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

perf: Perf #295

Merged
merged 4 commits into from
Jan 21, 2021
Merged

perf: Perf #295

merged 4 commits into from
Jan 21, 2021

Conversation

driftluo
Copy link
Collaborator

@driftluo driftluo commented Jan 16, 2021

in place decrypt on p2p bench

before:

After counting 10 cycles, estimated total time spent on task "10mb_benchmark_with_secio" is 2.6936522s                                 
task name: 10mb_benchmark_with_secio                                                                                                   
cycles: 100                                                                                                                            
total cost: 3.628672348s                                                                                                               
average: 36.286723ms                                                                                                                   
median: 45.029141ms                                                                                                                    
max: 52.898023ms                                                                                                                       
min: 20.852433ms

after:

After counting 10 cycles, estimated total time spent on task "10mb_benchmark_with_secio" is 2.1110216s
task name: 10mb_benchmark_with_secio
cycles: 100
total cost: 2.433076186s
average: 24.330761ms
median: 24.386613ms
max: 55.059342ms
min: 19.604614ms

@driftluo driftluo requested a review from TheWaWaR as a code owner January 16, 2021 09:09
@driftluo driftluo requested review from a team and doitian January 16, 2021 09:09
@driftluo driftluo changed the title Perf perf: Perf Jan 16, 2021
secio/src/codec/secure_stream.rs Outdated Show resolved Hide resolved
true
}

fn decrypt_in_place(&mut self, input: &mut bytes::BytesMut) -> Result<(), SecioError> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add a new fn to trait since the invoker has the mut reference already, can we change the original fn

fn decrypt(&mut self, input: &[u8]) -> Result<Vec<u8>, SecioError>

to

fn decrypt(&mut self, input: &mut [u8]) -> Result<(), SecioError>

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no new fn is added, OpenSSL will copy one more time, because OpenSSL bind does not have an in-place interface

Copy link
Collaborator Author

@driftluo driftluo Jan 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the same time, because &mut [u8] does not have shortened semantics(In other words, it doesn't have ownership, so it cannot be deleted/shortened), the delete tag operation on in-place cannot be performed on this type. Forcibly shortening its length with a pointer will cause a dangling pointer, so the type must be marked with shortening semantics type

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about change to BytesMut?

fn decrypt(&mut self, input: &mut BytesMut) -> Result<(), SecioError>

secio/src/crypto/ring_impl.rs Outdated Show resolved Hide resolved
secio/src/crypto/ring_impl.rs Outdated Show resolved Hide resolved
@driftluo driftluo merged commit b4edade into master Jan 21, 2021
@driftluo driftluo deleted the perf branch January 21, 2021 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants