speed up multiple invocations of counterfeiter #123
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In v6, we switched to use
go/packages
to load interfaces and packages, which gave us compatibility with go modules. It also included a significant degradation in speed that was mostly tolerable for single invocations ofcounterfeiter
, but unacceptable when multiple invocations were required (see #120).This PR implements two things:
packages.Load
and caches the results//go:generate
directives in a given package; for a package with 100 directivescounterfeiter
100 timescounterfeiter
will generate fakes for all 100 directives (leveraging the cache)counterfeiter
will be a no-op and exit without doing workThis yields impressive performance gains, but is still a regression relative to v5 performance (an approach which will not work for go modules), using
go generate
in https://github.com/cloudfoundry/cli/tree/7dc650d65b462a1df674b5697121b08362003cd0/cf/api as a benchmark:counterfeiter
v6 (with caching) (3.92 seconds) runs about 20.5 times faster than v6 (without caching) (80.45 seconds)counterfeiter
v6 (with caching) (3.92 seconds) runs about 5 times slower than v5 (0.78 seconds)counterfeiter v5
counterfeiter v6 (caching disabled)
counterfeiter v6
/cc @Samze @jamesjoshuahill @williammartin