uber-go / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
1.81k stars 103 forks source link

mockgen could be faster by invoking go list with different parameters. #180

Closed yves-tutti closed 2 weeks ago

yves-tutti commented 4 weeks ago

Actual behavior mockgen invokes go list as subcommand with -json.

Expected behavior it would execute much faster if invoking go list with -json=ImportPath,Name

To Reproduce

  1. Open a project with reasonably number of mockgen usage.
  2. time the run of all mockgen executions
  3. in mock/mockgen/mockgen.go, change the function createPackageMap
    • Change arguments to go list from "list", "-json" to "list", "-json=ImportPath,Name"

Background: go list is faster if we don't request the whole information in JSON format but only the two fields we are interested in: Name and ImportPath. There are conditionals like if listJsonFields.needAny("Deps", "DepsErrors") { in go's cmd/go/internal/list/list.go which are the reason that it's faster if we request only the subset of fields.

Verified in a scenario where generating 14 mocks from protobuf interfaces, 10 test runs:

The change will result in a diff of just 1 line change. No tests are affected. Since this project claims to be owned by uber (not sure how this plays out with the google history of the code), I'm not motivated to get involved in legal questions by signing a CLA nor do I understand why this projects needs such a CLA or want to discuss it.

I'd welcome if anyone uses these instructions to make a PR.