shotover / shotover-proxy

L7 data-layer proxy
https://docs.shotover.io
Apache License 2.0
83 stars 16 forks source link

Pass in Wrapper as &mut #1720

Closed rukai closed 1 month ago

rukai commented 1 month ago

This PR reduces the overhead of shotover's transform/chain abstractions by passing Wrapper by reference instead of by value.

Passing by value is usually not a performance issue in rust. However, in this case quite a few things collided to create a minor performance issue:

So to avoid this issue, this PR makes Transform::transform and other related functions take Wrapper by reference.

We can get most of the win by including only the largest fields in a referenced substruct as demonstrated by https://github.com/shotover/shotover-proxy/pull/1719 This would provide most of the benefits while avoiding some possible downsides:

Its hard to see if one way is truely better than the other, so I'm just taking this approach since its easier and probably has better performance

This PR yields consistent improvement across our basic chain benchmarks. loopback and nullsink have a consistent improvement of 6% (0.3us) and 4% (0.5us) respectively. The decode_request_metadata_drop benchmark improvement is noise, ignore it. Click through to the full codspeed performance report instead. These are incredibly small improvements but still valuable since these microsecond costs will be paid many times a second under heavy load. Additionally they will allow us to add further fields to the Wrapper type without performance cost. For example this will enable an alternative solution to https://github.com/shotover/shotover-proxy/pull/1717 without a performance cost.

codspeed-hq[bot] commented 1 month ago

CodSpeed Performance Report

Merging #1720 will improve performances by 10.06%

Comparing rukai:wrapper_ref (24b777a) with main (8438fa3)

Summary

⚡ 1 improvements ✅ 38 untouched benchmarks

Benchmarks breakdown

Benchmark main rukai:wrapper_ref Change
decode_request_metadata_drop 3.6 µs 3.3 µs +10.06%