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

Use whitelist to find go files, run find only once #10594

Merged
merged 2 commits into from
Mar 9, 2020

Conversation

silverwind
Copy link
Member

  • Use a whitelist-based approach to find *.go files so we can use standard find syntax. Also included is a change that files no longer pass a leading './' which should help performance further.

  • Instead of running find multiple times in make because of the lazy evaluation, run it only once and add the bindata files when the bindata tag is present

This is another huge speedup on my machine of around 2000%.

@silverwind
Copy link
Member Author

@guillep2k this should solve what you mentioned yesterday.

What's interesting is that even if I exclude the bindata files from GO_SOURCES, it still seems to be able to build in the bindata. To be sure they are still in the list, I did some extra work to have them included when the tag is present.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 3, 2020
@codecov-io
Copy link

codecov-io commented Mar 3, 2020

Codecov Report

Merging #10594 into master will decrease coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10594      +/-   ##
==========================================
- Coverage   43.62%    43.6%   -0.03%     
==========================================
  Files         588      588              
  Lines       82474    82483       +9     
==========================================
- Hits        35980    35966      -14     
- Misses      42029    42055      +26     
+ Partials     4465     4462       -3
Impacted Files Coverage Δ
models/repo_mirror.go 2.12% <0%> (-10.64%) ⬇️
services/pull/patch.go 61.93% <0%> (-2.59%) ⬇️
services/pull/temp_repo.go 29.05% <0%> (-2.57%) ⬇️
services/pull/check.go 53.04% <0%> (-2.44%) ⬇️
modules/queue/unique_queue_disk_channel.go 53.84% <0%> (-1.93%) ⬇️
modules/queue/workerpool.go 56.93% <0%> (-1.07%) ⬇️
modules/log/event.go 64.61% <0%> (-1.03%) ⬇️
services/mirror/mirror.go 18.75% <0%> (-0.66%) ⬇️
models/migrations/v130.go 0% <0%> (ø) ⬆️
services/pull/pull.go 35.88% <0%> (+0.88%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 123d386...4f4d5a5. Read the comment docs.

Makefile Outdated Show resolved Hide resolved
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 3, 2020
@guillep2k guillep2k requested a review from jolheiser March 3, 2020 22:35
Makefile Outdated Show resolved Hide resolved
@guillep2k
Copy link
Member

@guillep2k this should solve what you mentioned yesterday.

What's interesting is that even if I exclude the bindata files from GO_SOURCES, it still seems to be able to build in the bindata. To be sure they are still in the list, I did some extra work to have them included when the tag is present.

It's because the go compiler compiles the whole package. Including them in the source list is only needed for change detection.

@silverwind
Copy link
Member Author

One more potential point for optimization is PACKAGES which is also lazy-evaluated. Any pointers if this can be made one-time as well?

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 4, 2020
Makefile Show resolved Hide resolved
@guillep2k
Copy link
Member

One more potential point for optimization is PACKAGES which is also lazy-evaluated. Any pointers if this can be made one-time as well?

I don't think we need to have it dynamic (but keep on reading). AFAIU, the only reason for keeping it "dynamic" would be to support a forward reference. Consider the following:

GO_SOURCES = $(shell find $(SOURCE_DIRS) -name "*.go" -print)

[...]

SOURCE_DIRS = something something something

[...]

goexe: $(GO_SOURCES)
    ....

Here GO_SOURCES needs to be evaluated later because SOURCE_DIRS is not defined at the point GO_SOURCES is declared. If you'd use :=, then find would have no directory list and the results would be invalid.

I don't think that's the situation with PACKAGES.

Having said that, $(PACKAGES) seems to be used only within specific recipes (i.e. not for rules), like vet or test, so unless we're executing more than one of those rules in the same run, there will probably be no benefit in changing the definition.

@guillep2k guillep2k added this to the 1.12.0 milestone Mar 4, 2020
@lafriks lafriks added the topic/build PR changes how Gitea is built, i.e. regarding Docker or the Makefile label Mar 4, 2020
@silverwind
Copy link
Member Author

Right, PACKAGES can be handled in another PR. It does seem like a expensive operation so should bring more speed improvements.

@silverwind
Copy link
Member Author

@guillep2k your example contains the anti-pattern of using a variable before it was defined. I would not allow such usage, even with lazy evaluation.

Maybe there are linters for Makefiles that could catch such anti-patterns, a quick search leads me to https://github.com/mrtazz/checkmake.

@guillep2k
Copy link
Member

@guillep2k your example contains the anti-pattern of using a variable before it was defined. I would not allow such usage, even with lazy evaluation.

It was just a (lame) example, but quite a useful pattern in make, because then you've got a find functionality and many places where you can use it in different scenarios. We're using only one Makefile, but there are build systems with 10s or 100s that chain up and down. As with C++, you will need "foward declarations" at some point. 😄

@silverwind
Copy link
Member Author

@jolheiser it seems your review was requested. Would you mind?

Copy link
Member

@jolheiser jolheiser left a comment

Choose a reason for hiding this comment

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

LGTM

@guillep2k
Copy link
Member

Is this error coming from the PR itself or is it a glitch?

https://drone.gitea.io/go-gitea/gitea/22479/2/10

image

Although it only failed in MySQL builds, sounds Makefiley to me.

I'm restarting the CI just in case.

@silverwind
Copy link
Member Author

contrib is not included in GO_DIRS. I assume it should?

@silverwind
Copy link
Member Author

Added contrib which should get rid of these warnings.

@silverwind
Copy link
Member Author

silverwind commented Mar 6, 2020

Hmm that didn't do anything to the warnings. The warnings don't seem come from this PR. I see them on https://drone.gitea.io/go-gitea/gitea/22489/2/10 too.

contrib was included in the build before this change, but I deemed it unneccesary. It does contain three go files:

contrib/pr/checkout.go
contrib/fixtures/fixture_generation.go
contrib/environment-to-ini/environment-to-ini.go

Should I remove it again?

@guillep2k
Copy link
Member

I don't think /contrib should be part of the main build. There's a pr\#%: rule that uses it, though, but that's for manual invocation only.

@silverwind
Copy link
Member Author

ok, reverted

- Use a whitelist-based approach to find *.go files so we can use
  standard find syntax. Also included is a change that files no
  longer pass a leading './' which should help performance further.

- Instead of running `find` multiple times in make because of the
  lazy evaluation, run it only once and add the bindata files when
  the bindata tag is present

This is another huge speedup on my machine of around 2000%.
@silverwind
Copy link
Member Author

rebased, good to go

@guillep2k
Copy link
Member

Ping LG-TM

@guillep2k guillep2k merged commit 11f7fc5 into go-gitea:master Mar 9, 2020
@silverwind silverwind deleted the make-go-whitelist branch March 9, 2020 05:56
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. topic/build PR changes how Gitea is built, i.e. regarding Docker or the Makefile
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants