Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazily render mock diff output on successful match #1615

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mikeauclair
Copy link

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 and others added 5 commits June 24, 2024 20:29
* Stop querying for stack frames multiple times on CallerInfo()

* fix

* refill stack frame buffer after it's exhausted

* cleanup
@dolmen dolmen added pkg-mock Any issues related to Mock performance labels Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance pkg-mock Any issues related to Mock
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants