Skip to content

Speed up code generation, test compilation, and require Go 1.27.3 - #4067

Merged
raphael merged 2 commits into
v3from
codegen-performance-and-go-1.27.3
Oct 22, 2026
Merged

raphael merged 2 commits into
v3from
codegen-performance-and-go-1.27.3

Conversation

@raphael

@raphael raphael commented Oct 22, 2026

Copy link
Copy Markdown
Member

Generating code and running the generator test suites on large multi-service designs spent most of its time in repeated attribute deep copies, template re-parsing, full-file import formatting, reflection path allocations during design snapshot checks, and sequential go test -mod=mod subprocesses. This change reduces both goa gen execution time and the code generation test suite runtime while upgrading the module minimum to Go 1.27.3.

During code generation:

  • codegen.mappedObjectDefinition previously called expr.NewMappedAttributeExpr, which recursively cloned entire nested attribute graphs (DupAtt) just to strip :tag suffixes from top-level object fields during transform planning. expr.NewShallowMappedAttributeExpr now copies only the top-level object attribute and its immediate field slice while preserving shared UserType origin identity across sibling fields.
  • SectionTemplate.Write now caches parsed text/template instances for templates using the default TemplateFuncs() map instead of reparsing template text on every rendered section.
  • finalizeGoSource now formats only the package and import header through the first non-import declaration when imports.Process (FormatOnly: true) runs on files without //line directives, splicing the formatted import block onto the already-printed AST body instead of re-parsing and re-printing the entire file a second time.
  • captureDesignState now reuses a growable path buffer, caches struct field metadata per reflect.Type, and hashes directly into fnv.New128a() without allocating intermediate path strings on every visited node.

In the codegen test suites (codegen, codegen/service, codegen/generator, http/codegen, grpc/codegen, and jsonrpc/codegen), temporary test modules now pre-tidy go.mod and go.sum once per test binary and compile generated packages in parallel using -mod=readonly (and go build when no generated *_test.go files exist), cutting the combined test run from ~222s to ~56s.

@raphael
raphael merged commit 1bb6a01 into v3 Oct 22, 2026
5 checks passed
@raphael
raphael deleted the codegen-performance-and-go-1.27.3 branch October 22, 2026 05:59
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.

1 participant