testify
testify copied to clipboard
Lazily render mock diff output on successful match
trafficstars
Summary
- For mocks on functions that take complex types as arg,
Sprintf-ing theactualvalue 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>Requeststructs that are costly to%vviaSprintf.Sprintfshowed up as a tangible contributor to runtime performance when profiling some of our heavier tests. The below ~5s cpu time spent onSprintfgoes away completely here in one of our exemplar tests
Related issues
This includes the CallerInfo change from #1614
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)
Thank you for your contribution.