openssl icon indicating copy to clipboard operation
openssl copied to clipboard

Proposal for improving memory efficiency and speed

Open h-r-k-matsumoto opened this issue 3 years ago • 1 comments

Background

Our system handles large data, such as images larger than 10MB. I faced something that took a few seconds in the communication part of SSL.

Proposal

The part that could be improved is the buffering logic. The logic below will generate a large string object many times if nwrote is small and wbuffer is large. https://github.com/ruby/openssl/blob/master/lib/openssl/buffering.rb#L358

@wbuffer[0, nwrote] = ""

I think it is more efficient to take a specific size from the wbuffer and write it, as follows.

I'll submit a pull request with a result of investigation for memory allocation and speed.

h-r-k-matsumoto avatar Jan 02 '22 11:01 h-r-k-matsumoto

It might make even more sense for us to rewrite this using C and/or IO::Buffer to experiment with performance.

ioquatix avatar Jan 02 '22 23:01 ioquatix