saucelabs / forwarder

Forwarder is a production-ready, fast MITM proxy with PAC support. It's suitable for debugging, intercepting and manipulating HTTP traffic. It's used as a core component of Sauce Labs Sauce Connect Proxy.
https://forwarder-proxy.io
Mozilla Public License 2.0
218 stars 13 forks source link

perf: parallel io.Copy #664

Closed mmatczuk closed 2 months ago

mmatczuk commented 7 months ago

The io.Copy implementation is synchronous. It reads and writes in a for loop on a single thread. When read and write costs are high (i.e. using net.Conn) it cal halve the performance.

We could easily optimize that by prefetching data while writing.

Now

R R R
 W W W

Desired

RRR
 WWW

Implementation idea:

Note use subslice with capacity [start:len:cap] syntax.

mmatczuk commented 2 months ago

The idea was implemented in https://github.com/saucelabs/forwarder/pull/834 but did not yield the expected results.