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

feat: detect when go mod tidy and build scaffolding is needed #3360

Merged
merged 2 commits into from
Nov 8, 2024

Conversation

matt2e
Copy link
Collaborator

@matt2e matt2e commented Nov 8, 2024

closes #3129

Increases performance of go builds by 0.5s-0.8s in some cases.

Changes:

  • Track if any thing has changed that would require us to
    • call go mod tidy (in either the main module directory, or in the build directory)
    • scaffold the build template (if we scaffold, we also need to run go mod tidy)
  • If a build fails for any reason, reset ongoing build state so next time we always rebuild everything.

Trigger details:

  • If we detect changes in go.mod, go.sum or types.ftl.go, always rebuild fully
  • If the list of imported packages has changed, go mod tidy is required in the module's directory
  • If the MainModuleContext has changed in any way, then the build template needs to be scaffolded, and go mod tidy needs to be run in .ftl/go/main

Performace:

  • Scaffolding is super fast
  • Running go mod tidy usually takes around 0.5-0.8s (but can take more if network requests are required)
  • The 2 go mod tidy executions are run in parallel, so if either is required then there is no real performance gain. If neither is required then we see the performance improvement.
  • The rest of the build time is split between extracting schema (0.5-1.5s) and compiling (0.5-1.5s)

@matt2e matt2e requested review from a team and alecthomas as code owners November 8, 2024 03:27
@matt2e matt2e requested review from stuartwdouglas and removed request for a team November 8, 2024 03:27
@ftl-robot ftl-robot mentioned this pull request Nov 8, 2024
@matt2e matt2e marked this pull request as draft November 8, 2024 03:35
@matt2e matt2e marked this pull request as ready for review November 8, 2024 04:28
@matt2e matt2e merged commit fa14481 into main Nov 8, 2024
94 checks passed
@matt2e matt2e deleted the matt2e/detect-when-tidy branch November 8, 2024 05:24
if err := filesTransaction.Begin(); err != nil {
return moduleSch, nil, fmt.Errorf("could not start a file transaction: %w", err)
}
defer func() {
if terr := filesTransaction.End(); terr != nil {
err = fmt.Errorf("failed to end file transaction: %w", terr)
}
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we log this error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All errors returned from this function get logged by the build engine, so we don't need to double log here.

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

Successfully merging this pull request may close these issues.

go plugin to track if go mod tidy needs to run
2 participants