Skip to content

cmd/go: module graph pruning and lazy module loading #36460

Closed

Description

@bcmills

I propose to change cmd/go to avoid loading transitive module dependencies
that have no observable effect on the packages to be built.

The key insights that lead to this approach are:

  1. If no package in a given dependency module is ever (even transitively)
    imported by any package loaded by an invocation of the go command, then an
    incompatibility between any package in that dependency and any other package
    has no observable effect in the resulting program(s). Therefore, we can
    safely ignore the (transitive) requirements of any module that does not
    contribute any package to the build.

  2. We can use the explicit requirements of the main module as a coarse filter
    on the set of modules relevant to the main module and to previous
    invocations of the go command.

Based on those insights, I propose to change the go command to retain more
transitive dependencies in go.mod files and to avoid loading go.mod files
for “irrelevant” modules, while still maintaining high reproducibility for build
and test operations.

Design doc: http://golang.org/design/36460-lazy-module-loading.

Activity

  1. added
    WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.
    on Jan 8, 2020
  2. added this to the Go1.15 milestone on Jan 8, 2020
  3. gopherbot commented on Feb 3, 2020

    @gopherbot
    Contributor

    Change https://golang.org/cl/217557 mentions this issue: cmd/go: add a regression test for package import cycles guarded by build tags

  4. gopherbot commented on Feb 19, 2020

    @gopherbot
    Contributor

    Change https://golang.org/cl/220080 mentions this issue: design/36460: add design for lazy module loading

  5. removed
    WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.
    on Feb 19, 2020
  6. bcmills commented on Feb 19, 2020

    @bcmills
    ContributorAuthor

    A detailed design is in CL 220080.

    (You can view the rendered Markdown by opening the .md file at the latest patch set and clicking the gitiles link.)

  7. added
    early-in-cycleA change that should be done early in the 3 month dev cycle.
    on Feb 19, 2020
  8. ChrisHines commented on Feb 20, 2020

    @ChrisHines
    Contributor

    For modules that are tidy:

    The module versions recorded in the go.mod file would be exactly those listed in vendor/modules.txt, if present.

    👍 I think that is a nice property to have. I have some projects for which go mod vendor is sane, but go mod tidy updates the go.mod file in undesirable ways due to test-of-test dependencies. If I understand this proposal correctly that problem would go away.

  9. bcmills commented on Feb 20, 2020

    @bcmills
    ContributorAuthor

    I added a few examples (in our usual cmd/go script test format) to the design doc.

    @ChrisHines, the third example explicitly covers the behavior for test-of-test dependencies.

  10. bcmills commented on Feb 21, 2020

    @bcmills
    ContributorAuthor

    CC @julieqiu since this may affect how we display dependencies on pkg.go.dev.

    CC @heschik, @dmitshur because this may affect the package search algorithms used by goimports and godoc.

    CC @bep because I seem to recall that Hugo is doing something unusual with module dependencies independent of Go package imports. (But note that we are unlikely to actively support the use of Go modules for purposes other than compiling Go source code.)

  11. bep commented on Feb 21, 2020

    @bep
    Contributor

    But note that we are unlikely to actively support the use of Go modules for purposes other than compiling Go source code.

    Our unusual usage is fairly well anchored in the "Go project". That said, I have read your design document twice, and I think this is a good thing (even for our unusual use) -- but it would be easier to determine with a prototype (I find this topic to be a little bit of a mind twister and I don't fully understand the examples in the document).

  12. 288 remaining items

  13. added a commit that references this issue on May 17, 2022
  14. moved this to Accepted in Proposalson Aug 10, 2022
  15. added a commit that references this issue on Oct 10, 2022
  16. removed this from Proposalson Oct 19, 2022
  17. added a commit that references this issue on Feb 16, 2023
  18. added a commit that references this issue on May 17, 2023
  19. locked and limited conversation to collaborators on Jun 23, 2023
  20. added a commit that references this issue on Apr 29, 2024
    63b968f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.Proposal-Acceptedearly-in-cycleA change that should be done early in the 3 month dev cycle.modules

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions