Skip to content

refactor: faster go codegen - #780

Draft
wim07101993 wants to merge 4 commits into
mainfrom
refactor/faster-codegen
Draft

refactor: faster go codegen#780
wim07101993 wants to merge 4 commits into
mainfrom
refactor/faster-codegen

Conversation

@wim07101993

Copy link
Copy Markdown
Member

Summary

I noticed that the go generate ./... command was getting slow on my computer so I started researching what was up:

Impact

Command Before After
go generate ./... 13.9s 5.1s 2.7x
moon run server:generate / server:check-generate 13.9s 3.3s 4.2x

Where the time went

Package Before After
internal/domain 5398ms 2134ms
internal/service 5181ms 886ms
internal/crypto 1219ms 612ms
api 432ms 469ms
everything else ~1000ms ~1300ms
serial total ~13.9s ~5.1s
wall clock, packages in parallel ~3.3s

The two numbers differ because mockgen's cost is per invocation, not per interface:
it type-loads the package before mocking anything, so a directive covering one
interface costs the same ~800ms as one covering twenty. internal/service had six
such directives and paid the load six times.

After the change the run is no longer a sum — it's a critical path of
api (469ms) + internal/domain (2134ms), with every other package finishing
underneath it.

Validation

  • go generate ./...

Release notes / changeset

  • No changeset required — no shipped behavior changed.

Notes

Copilot AI review requested due to automatic review settings August 7, 2026 13:05
@vercel

vercel Bot commented Aug 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nextgen Ready Ready Preview Aug 7, 2026 2:23pm
nextgen-docs Ready Ready Preview Aug 7, 2026 2:23pm
nextgen-mock-zitadel Ready Ready Preview Aug 7, 2026 2:23pm

Request Review

@wim07101993 wim07101993 moved this from Inbox to Ready in Engineering Kanban Aug 7, 2026
@zitadel-kanban zitadel-kanban Bot moved this from Ready to Inbox in Engineering Kanban Aug 7, 2026
@wim07101993 wim07101993 changed the title Refactor/faster codegen refactor: faster go codegen Aug 7, 2026
@wim07101993
wim07101993 marked this pull request as draft August 7, 2026 13:07
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: ef09c17

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR speeds up Go code generation in the monorepo by (1) consolidating many per-interface mockgen directives into a single package-level invocation for internal/{service,domain,crypto}, and (2) running go generate across directive-holding directories concurrently (while keeping api generation serialized first to avoid source-read/write races). It also updates the server Moon tasks and repository guidance to use the new generator.

Changes:

  • Add scripts/go-generate.mjs to discover //go:generate directives and run package generation in parallel with an api-first phase boundary.
  • Consolidate mock generation in internal/{service,domain,crypto} into single generate.go directives, collapsing multiple generated mock files into one per package.
  • Update Moon tasks + AGENTS.md guidance, and add an empty changeset describing the non-shipping performance improvement.

Reviewed changes

Copilot reviewed 36 out of 37 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
scripts/go-generate.mjs New Node script to discover //go:generate directives and run generation concurrently with an api-first phase.
scripts/check-go-generate.mjs Switches “check generate drift” to call the new generator runner and handle errors without stack noise.
internal/service/token.go Removes per-interface mockgen directive (now consolidated).
internal/service/statement.go Removes large per-file mockgen directive (now consolidated).
internal/service/session.go Removes per-interface mockgen directive (now consolidated).
internal/service/mocks/token.mock.go Deletes standalone generated mock file (consolidated into service.mock.go).
internal/service/mocks/session.mock.go Deletes standalone generated mock file (consolidated into service.mock.go).
internal/service/mocks/service.mock.go Regenerated: now contains combined mocks for service/database/auth/session/token/key-related interfaces.
internal/service/mocks/keys.mock.go Deletes standalone generated mock file (consolidated into service.mock.go).
internal/service/mocks/database.mock.go Deletes standalone generated mock file (consolidated into service.mock.go).
internal/service/mocks/auth_attempt.mock.go Deletes standalone generated mock file (consolidated into service.mock.go).
internal/service/keys.go Removes per-interface mockgen directive (now consolidated).
internal/service/generate.go New package-level mockgen directive for the entire internal/service package.
internal/service/database.go Removes per-interface mockgen directive (now consolidated).
internal/service/auth_attempt.go Removes per-interface mockgen directive for secondary ports (now consolidated).
internal/domain/mock/json_schema.mock.go Deletes standalone generated mock file (consolidated into domain.mock.go).
internal/domain/mock/flow_passkey_registration.mock.go Deletes standalone generated mock file (consolidated into domain.mock.go).
internal/domain/mock/flow_on_success.mock.go Deletes standalone generated mock file (consolidated into domain.mock.go).
internal/domain/mock/flow_field_resolver.schema.mock.go Deletes standalone generated mock file (consolidated into domain.mock.go).
internal/domain/mock/flow_field_resolver.mock.go Deletes standalone generated mock file (consolidated into domain.mock.go).
internal/domain/mock/flow_auth_attempt.mock.go Deletes standalone generated mock file (consolidated into domain.mock.go).
internal/domain/mock/domain.mock.go New combined generated mocks for multiple domain interfaces.
internal/domain/json_schema.go Removes per-interface mockgen directive (now consolidated).
internal/domain/generate.go New package-level mockgen directive for the entire internal/domain package (keeps enumer directives near types).
internal/domain/flow_passkey_registration.go Removes per-interface mockgen directive (now consolidated).
internal/domain/flow_on_success.go Removes per-interface mockgen directive (now consolidated).
internal/domain/flow_field_resolver.go Removes per-interface mockgen directive (now consolidated).
internal/domain/flow_field_resolver_schema.go Removes per-interface mockgen directive (now consolidated).
internal/domain/flow_auth_attempt.go Removes per-interface mockgen directive (now consolidated).
internal/crypto/mock/hash.mock.go Deletes standalone generated mock file (consolidated into crypto.mock.go).
internal/crypto/mock/crypto.mock.go Regenerated: now also includes hash-related mocks in addition to encryption-related mocks.
internal/crypto/hash.go Removes per-interface mockgen directive (now consolidated).
internal/crypto/generate.go New package-level mockgen directive for the entire internal/crypto package.
internal/crypto/encryption.go Removes per-interface mockgen directive (now consolidated).
apps/server/moon.yml Updates server:generate to run the new Node generator script; extends inputs accordingly.
AGENTS.md Updates contributor guidance to prefer moon run server:generate (with note that bare go generate ./... remains valid but slower).
.changeset/parallel-go-codegen.md Adds an empty changeset documenting the performance-focused refactor.
Files not reviewed (1)
  • internal/domain/mock/domain.mock.go: Generated file

Comment thread scripts/go-generate.mjs
Comment thread apps/server/moon.yml
Comment thread apps/server/moon.yml
Comment thread .changeset/parallel-go-codegen.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Inbox

Development

Successfully merging this pull request may close these issues.

2 participants