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

Speed up go generate #6687

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

arzonus
Copy link
Contributor

@arzonus arzonus commented Feb 25, 2025

What changed?
Makefile has been changed:

  • If gowrap or mockgen are being installed, binaries will be replaced by scripts from scripts/gogenerate folder

scripts/gogenerate folder has been added. This folder contains custom scripts designed to replace the original binaries invoked during go generate commands.

The changes will not be automatically used, as a developer require to run make clean to clean up binaries.

Why?
In many cases, regenerating files during go generate is unnecessary if the source files (or other dependencies) have
not been updated. These scripts introduce a simple optimization: they check file modification times and skip regeneration if the output file is already up-to-date. go-generate is a mandatory step of make pr command that should be executed each time when you push changes to your branch.

make pr has been speeded up 13x times from 2.25m to 18 seconds.

Before the diff

➜  cadence git:(master) time make pr
make tidy...
make go-generate...
make copyright...
make fmt...
make lint...
make pr  259.16s user 578.92s system 577% cpu 2:25.08 total

After the diff

➜  cadence git:(speed-up-go-generate) time make pr
make tidy...
make go-generate...
make copyright...
make fmt...
make lint...
make pr  42.21s user 43.61s system 454% cpu 18.886 total

How did you test it?

  1. Run make pr on master and on branch to compare results
  2. (WIP) Created a PR based on this PR that contains changes in some interfaces and still has changed mocks and wrapper go files to verify that the logic works well.

Potential risks
go-generate will not be called for changed files. Mostly these changes will make the source code not compilable or testable.

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