Skip to content

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

@yves-tutti

Description

@yves-tutti

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions