Skip to content

optimize(generate): speed up make generate flow - #23519

Merged
kalverra merged 17 commits into
developfrom
fasterGenerate
Aug 25, 2026
Merged

optimize(generate): speed up make generate flow#23519
kalverra merged 17 commits into
developfrom
fasterGenerate

Conversation

@kalverra

@kalverra kalverra commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Intent

Speed up the make generate flow locally and in CI

Big Changes

Pruned make rm-mocked Search

Switches mock cleanup to use rg (with a pruned find fallback) targeting only .go files while excluding .git, node_modules, .yarn, and vendor directories, piping directly to xargs rm -f.

The previous grep -rl unselectively crawled git object packs, node modules, and caches, taking >30s. Pruning unneeded paths cuts execution time to <0.2s.

Exact Tool Version Checks Before Install

Adds binary presence and version verification (go version -m or --version) for gomods, mockery, codecgen, protoc-gen-go, protoc-gen-go-grpc, protoc-gen-go-wsrpc, and modgraph before invoking go install.

Unconditional go install commands query module proxies and run build pipelines even when binaries already exist, creating 5–10s+ of cumulative latency on every make generate run. Checking binary metadata locally skips rebuilds in <1ms.

Concurrent Mockery Generation

Finds .mockery.yaml configuration files while pruning ignored directories and executes mockery across configurations concurrently using xargs -n1 -P0.

Running mockery in parallel across the root and submodule configurations reduces wall-clock execution time during full repo code generation.

Githook Directive Detection & Optimized Execution

Enhances tools/githooks/internal/generate with streaming //go:generate directive detection, early non-code file filtering, deduplicated module discovery, MOCKERY_BIN resolution, and bounded errgroup concurrency.

Ensures git pre-commit hooks detect changes requiring code generation accurately without wasteful full-file memory buffering or unbounded subprocess spawning.

Small Changes

  • Added unit tests in tools/githooks/internal/generate/generate_test.go covering //go:generate directive detection, non-code asset skipping, parallel execution, and operator_ui/TAG trigger handling.
  • Pinned MOCKERY_VERSION = 2.53.6 variable in GNUmakefile for consistent reference across commands and version checks.
  • Removed modgraph from the default generate target dependencies. This is redundant.

Results

Local - Cold Cache

Command / Step Baseline (develop) After (rg mode) After (find fallback) Improvement (rg) Improvement (find)
make rm-mocked ~33.00s 0.18s 0.48s ~180x faster ~68x faster
Tool check / prerequisites (mockery, protoc, gomods, etc.) ~50.00s 46.00s 46.00s ~1.1x faster ~1.1x faster
Package discovery & go generate ~16.00s 14.00s 14.50s ~1.15x faster ~1.1x faster
Mockery execution (. & deployment/) ~9.00s 7.80s 7.80s ~1.15x faster ~1.15x faster
Total make rm-mocked + make generate flow 107.86s 68.04s 69.00s ~1.6x faster ~1.55x faster

Local - Warm Cache

Command / Step Baseline (develop) After (rg mode) After (find fallback) Improvement (rg) Improvement (find)
make rm-mocked 32.88s 0.11s 0.59s ~299x faster ~56x faster
Tool check / prerequisites (mockery, protoc, gomods, etc.) 42.65s 0.29s 0.29s ~147x faster ~147x faster
Package discovery & go generate 4.45s 2.67s 3.32s ~1.7x faster ~1.3x faster
Mockery execution (. & deployment/) 4.56s 3.59s 3.59s ~1.3x faster ~1.3x faster
Total make rm-mocked + make generate flow 84.54s 8.88s 11.30s ~9.5x faster ~7.5x faster

CI

image

@kalverra
kalverra requested review from a team as code owners August 24, 2026 18:45
@kalverra
kalverra requested a lite review from Copilot and removed request for skudasov August 24, 2026 18:45
@github-actions

Copy link
Copy Markdown
Contributor

👋 kalverra, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

@github-actions

Copy link
Copy Markdown
Contributor

✅ No conflicts with other open PRs targeting develop

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

Risk Rating: MEDIUM — Changes affect developer/CI tooling (make generate, rm-mocked) and githook-driven codegen triggers. Failures here can block local workflows and CI generation steps.

This PR focuses on speeding up the make rm-mocked + make generate workflow by reducing unnecessary scanning/work and adding smarter trigger conditions for generation (including githooks parity).

Changes:

  • Update githooks generation triggers to also react to //go:generate directives in changed .go files and to operator_ui/TAG changes (triggering ./core/web generation).
  • Optimize make generate and rm-mocked by using rg when available (with pruned find fallback) and by caching/install-guarding tool prerequisites (plus pinned mockery version checks).
  • Run mockery configs concurrently via xargs parallelism.

Scrupulous human review recommended (tooling correctness/portability):

  • GNUmakefile generate / rm-mocked pipelines and their macOS/BSD portability (notably xargs behavior, -P0, and argument forms passed to go generate).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
tools/githooks/internal/generate/generate.go Adds trigger logic for operator_ui/TAG and for changed .go files containing //go:generate.
tools/githooks/internal/generate/generate_test.go Adds test coverage for the new githooks triggers.
GNUmakefile Reworks make generate/rm-mocked to speed up discovery/execution and to reduce redundant tool installs.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread GNUmakefile Outdated
Comment thread GNUmakefile Outdated
Comment thread GNUmakefile Outdated
@kalverra
kalverra enabled auto-merge August 24, 2026 18:56
@trunk-io

trunk-io Bot commented Aug 24, 2026

Copy link
Copy Markdown

Static BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

Comment thread GNUmakefile Outdated
Comment thread GNUmakefile Outdated
Comment thread GNUmakefile
@jmank88

jmank88 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

When I run gomods -go generate -run xxx ./... plainly, the tooling traverses all of the modules in 1-2 seconds. Where are ~10s of speedup coming from?

@kalverra

Copy link
Copy Markdown
Collaborator Author

@jmank88

When I run gomods -go generate -run xxx ./... plainly, the tooling traverses all of the modules in 1-2 seconds. Where are ~10s of speedup coming from?

The stats in the PR description were using a cold cache for "Before", but a warm cache for "After", which made the original approach look much worse than it was in a fair fight. Have updated to comparisons.

@kalverra
kalverra requested review from jmank88 and tvc-robsondebraga and a lite review from Copilot August 24, 2026 20:28

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

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

Comment thread tools/githooks/internal/generate/generate.go
Comment thread tools/githooks/internal/generate/generate.go
Comment thread GNUmakefile Outdated
Comment thread GNUmakefile Outdated
erikburt
erikburt previously approved these changes Aug 25, 2026
@jmank88

jmank88 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Should this speedup translate to CI as well? Latest develop vs. this PR looks like a slowdown from 4m to 5m:
Develop: https://github.com/smartcontractkit/chainlink/actions/runs/32836945436/job/97767815435
PR: https://github.com/smartcontractkit/chainlink/actions/runs/32776689180/job/97589350020?pr=23519

Comment thread GNUmakefile Outdated
@cl-sonarqube-production

Copy link
Copy Markdown

@kalverra

kalverra commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator Author

@jmank88

Should this speedup translate to CI as well? Latest develop vs. this PR looks like a slowdown from 4m to 5m: Develop: https://github.com/smartcontractkit/chainlink/actions/runs/32836945436/job/97767815435 PR: https://github.com/smartcontractkit/chainlink/actions/runs/32776689180/job/97589350020?pr=23519

Yes, it translates to CI, but not a whole lot. The bigger advantages were actually in my latest commits when I moved things over from an expensive GitHub Actions runner to use runs-on instead.

image

@kalverra
kalverra added this pull request to the merge queue Aug 25, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 25, 2026
@kalverra
kalverra added this pull request to the merge queue Aug 25, 2026
Merged via the queue into develop with commit c40ac9f Aug 25, 2026
224 checks passed
@kalverra
kalverra deleted the fasterGenerate branch August 25, 2026 20:12
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.

5 participants