voodoodyne / subethasmtp

SubEtha SMTP is a Java library for receiving SMTP mail
Other
352 stars 139 forks source link

improve performance of CRLFOutputStream #59

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
(I'm not 100% sure my analysis is correct so please excuse me if I have got it 
wrong).

The CRLFOutputStream unnecessarily splits output byte [] buffers into multiple 
calls to write. CRLFOutputStream ensures that end-of-line is always terminated 
with CRLF, and so when it encounters 'naked' CRs or LFs it will convert them 
into proper line endings. In the case it encounters a proper line ending 
however, it will still split the input buffer causing unnecessary calls to 
write.

The attached patch attempts to properly detect proper line ends to avoid 
splitting write calls unnecessarily.

For large message attachments this can improve performance dramatically.

Original issue reported on code.google.com by miah.n...@gmail.com on 5 Mar 2013 at 8:52

Attachments:

GoogleCodeExporter commented 9 years ago
I do not wonder that you are not 100% sure in the analysis. This is very old, 
and worse still, optimized code from Apache James. This class 
(CRLFOutputStream) is strongly tied to ExtraDotOutputStream through inheritance 
and their responsibilities become mixed.

The writeChunk method is overriden in ExtraDotOutputStream class, and it 
expects a full or partial line as input. 

Your patch would pass an input which contains more lines, therefore it is not 
correct.

Interestingly, the original class is wrong too. Its write(int) method bypasses 
writeChunk altogether. But this does not cause any issues for us, because that 
function is not used in SubEthaSMTP.

An actual solution is not far however. I believe that the two classes can be 
refactored, so that they become separated completely. Instead of inheritance, 
CRLFOutputStream should wrap the ExtraDotOutputStream. In this way you can 
optimize the write(buffer) method of both class, and still not create a mess. 
If you write a new patch, please add the result of a basic measurement, like in 
your other performance related patch, so we can apply it as happily as in that 
case.

Original comment by hontvari@flyordie.com on 11 Mar 2013 at 11:08

GoogleCodeExporter commented 9 years ago

Original comment by hontvari@flyordie.com on 12 May 2013 at 12:50