ryan961 / memo

https://github.com/ryan961/memo/issues
Creative Commons Zero v1.0 Universal
0 stars 0 forks source link

Go Build: Debugging Go compiler performance in a large codebase #6

Open ryan961 opened 9 months ago

ryan961 commented 9 months ago

🤖 AI Summary

This article outlines various strategies for speeding up Go builds, making them significantly faster. It highlights practical steps such as reducing binary size, leveraging caching effectively, and parallelizing builds. The authors detail their hands-on experience with optimization and provide insights into how incremental builds, build tags, and avoiding cgo can lead to faster build times. These techniques are particularly useful for teams looking to streamline their development and deployment processes in projects using the Go programming language.

🖇️ Details

🔖 Note

This article provides a good idea for deep optimization of the go build compilation process (although the projects I am currently encountering have not reached such requirements 🙃). Here are two interesting points to note:

  1. By passing some interesting flags (-debug-trace...) to go build, generate a trace file and import it into visualization tools like Perfetto for targeted compilation optimization

    • -debug-actiongraph - this tells you what the compiler is doing at different points, and can be inspected with https://github.com/icio/actiongraph.
    • -debug-trace - this produces a trace, which can be visualised in a tool like Perfetto.
  2. Using depguard (a great linter that can rule out import cycles), restrict pkg/domain from importing anything beyond the standard library

    linters:
    enable:
     - depguard
     - ...
    linter-settings:
    depguard:
     rules:
     domain-no-deps:
       files:
         # this rule applies to anything within pkg/domain
         - "**/pkg/domain/***"
         # Exclude any test files which can import whateverthey like
         - "!$test"
       allow:
         - "$gostd"