testify icon indicating copy to clipboard operation
testify copied to clipboard

Lazily render mock diff output on successful match

Open mikeauclair opened this issue 1 year ago • 2 comments
trafficstars

Summary

  • For mocks on functions that take complex types as arg, Sprintf-ing the actual value can be costly. Switch successful matches to use thunks to lazily render their output, and fully avoid rendering their output when there are no differences since we return a constant string in that case anyways

Changes

  • Switch to a string builder for accumulating output for better performance even when we do render

Motivation

  • We heavily use mocks at DevotedHealth, and use them frequently in gRPC contexts where we're mocking RPCs that take <Whatever>Request structs that are costly to %v via Sprintf. Sprintf showed up as a tangible contributor to runtime performance when profiling some of our heavier tests. The below ~5s cpu time spent on Sprintf goes away completely here in one of our exemplar tests
Screenshot 2024-06-25 at 12 16 35 PM

Related issues

mikeauclair avatar Jun 25 '24 16:06 mikeauclair

This includes the CallerInfo change from #1614

brackendawson avatar Oct 30 '24 11:10 brackendawson

I'd like it to be separated from #1614, they're not dependant on one another, right?

I honestly don't remember if they are or are not given how long it's been since I wrote this. I can try to take a pass on cleaning this and the other PR up after next week (short week for thanksgiving in the states)

mikeauclair avatar Nov 23 '24 18:11 mikeauclair

Thank you for your contribution.

brackendawson avatar May 06 '25 10:05 brackendawson