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

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

Closed
yves-tutti opened this issue Jun 5, 2024 · 0 comments
Closed

Comments

@yves-tutti
Copy link

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:

  • Originally: 10.21s, 15.17s, 12.86s, 13.65s, 14.36s, 13.62s, 13.39s, 13.10s, 12.80s, 12.64s
  • With Change: 8.49s, 9.52s, 9.28s, 9.16s, 9.20s, 8.79s, 9.21s, 9.17s, 9.34s, 9.58s
  • Average difference: 13.18s vs. 9.174s.

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.

r-hang pushed a commit that referenced this issue Jun 18, 2024
This PR implements the changes described in issue #180 to speedup mock
generation
@r-hang r-hang closed this as completed Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants