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

fix: Remove excessive recursive variable expansions #781

Conversation

mpatlasov
Copy link
Contributor

Modern GNU make (version >= 4.4) has backward-incompatible feature:

  • WARNING: Backward-incompatibility!
    Previously makefile variables marked as export were not exported to commands
    started by the $(shell ...) function. Now, all exported variables are
    exported to $(shell ...). If this leads to recursion during expansion, then
    for backward-compatibility the value from the original environment is used.

This makes any invocation of make command very costly. Compare the performance of make 4.3 vs. 4.4:

$ time ~/Sources/make-4.3/make smb ARCH=$(go env GOARCH)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "-X github.com/kubernetes-csi/csi-driver-smb/pkg/smb.driverVersion=v1.15.0 -X github.com/kubernetes-csi/csi-driver-smb/pkg/smb.gitCommit=f5ced814f628ddee2c9f3e6af505c5a6123e50f4 -X github.com/kubernetes-csi/csi-driver-smb/pkg/smb.buildDate=2024-05-15T00:00:09Z -s -w -extldflags "-static"" -mod vendor -o _output/amd64/smbplugin ./cmd/smbplugin

real	0m38.504s
user	3m50.580s
sys	0m23.502s

$ time ~/Sources/make-4.4/make smb ARCH=$(go env GOARCH)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "-X github.com/kubernetes-csi/csi-driver-smb/pkg/smb.driverVersion=v1.15.0 -X github.com/kubernetes-csi/csi-driver-smb/pkg/smb.gitCommit=f5ced814f628ddee2c9f3e6af505c5a6123e50f4 -X github.com/kubernetes-csi/csi-driver-smb/pkg/smb.buildDate=2024-05-15T00:04:04Z -s -w -extldflags "-static"" -mod vendor -o _output/amd64/smbplugin ./cmd/smbplugin

real	16m59.851s
user	13m16.490s
sys	13m46.418s

The same variables are evaluated again and again millions times:

$ rpm -qf /usr/bin/make
make-4.4.1-6.fc40.x86_64

$ /usr/bin/make -d smb ARCH=$(go env GOARCH) 2>&1 |grep "not recursively expanding.*to export to shell function" |wc -l
2171342

The patch doesn't change user-visible behavior of Makefile, but makes make command as performant as it used to be in case of make 4.3.

What type of PR is this?

/kind bug

What this PR does / why we need it:

Modern make (>= 4.4) builds csi driver extremely slowly.

Release note:

none

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 15, 2024
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 15, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @mpatlasov. Thanks for your PR.

I'm waiting for a kubernetes-csi member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label May 15, 2024
@andyzhangx
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 15, 2024
@coveralls
Copy link

coveralls commented May 15, 2024

Pull Request Test Coverage Report for Build 9215890520

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 79.093%

Totals Coverage Status
Change from base Build 9200774924: 0.0%
Covered Lines: 942
Relevant Lines: 1191

💛 - Coveralls

@mpatlasov
Copy link
Contributor Author

/retest-required

3 similar comments
@mpatlasov
Copy link
Contributor Author

/retest-required

@mpatlasov
Copy link
Contributor Author

/retest-required

@mpatlasov
Copy link
Contributor Author

/retest-required

Makefile Show resolved Hide resolved
Modern GNU make (version >= 4.4) has backward-incompatibile feature:

> * WARNING: Backward-incompatibility!
>  Previously makefile variables marked as export were not exported to commands
>  started by the $(shell ...) function.  Now, all exported variables are
>  exported to $(shell ...).  If this leads to recursion during expansion, then
>  for backward-compatibility the value from the original environment is used.

This makes any invocation of `make` command very costly. Compare the performance of make 4.3 vs. 4.4:
```
$ time ~/Sources/make-4.3/make smb ARCH=$(go env GOARCH)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "-X github.com/kubernetes-csi/csi-driver-smb/pkg/smb.driverVersion=v1.15.0 -X github.com/kubernetes-csi/csi-driver-smb/pkg/smb.gitCommit=f5ced814f628ddee2c9f3e6af505c5a6123e50f4 -X github.com/kubernetes-csi/csi-driver-smb/pkg/smb.buildDate=2024-05-15T00:00:09Z -s -w -extldflags "-static"" -mod vendor -o _output/amd64/smbplugin ./cmd/smbplugin

real	0m38.504s
user	3m50.580s
sys	0m23.502s

$ time ~/Sources/make-4.4/make smb ARCH=$(go env GOARCH)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "-X github.com/kubernetes-csi/csi-driver-smb/pkg/smb.driverVersion=v1.15.0 -X github.com/kubernetes-csi/csi-driver-smb/pkg/smb.gitCommit=f5ced814f628ddee2c9f3e6af505c5a6123e50f4 -X github.com/kubernetes-csi/csi-driver-smb/pkg/smb.buildDate=2024-05-15T00:04:04Z -s -w -extldflags "-static"" -mod vendor -o _output/amd64/smbplugin ./cmd/smbplugin

real	16m59.851s
user	13m16.490s
sys	13m46.418s
```

The same variables are evaluated again and again millions times:
```
$ rpm -qf /usr/bin/make
make-4.4.1-6.fc40.x86_64

$ /usr/bin/make -d smb ARCH=$(go env GOARCH) 2>&1 |grep "not recursively expanding.*to export to shell function" |wc -l
2171342
```

The patch doesn't change user-visible behavior of Makefile, but makes `make` command as performant as it used to be in case of make 4.3.
@mpatlasov mpatlasov force-pushed the Remove-excessive-recursive-variable-expansions branch from 25daed3 to b022182 Compare May 23, 2024 22:51
@mpatlasov
Copy link
Contributor Author

force-pushed simple change: no need to check ifndef GIT_COMMIT because it's OK to set it once-and-for-all as the SHA1 hash of the current commit (#781 (comment) )

@andyzhangx
Copy link
Member

/retest

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented May 24, 2024

@mpatlasov: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-csi-driver-smb-sanity b022182 link true /test pull-csi-driver-smb-sanity

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@andyzhangx andyzhangx merged commit d664482 into kubernetes-csi:master May 24, 2024
18 of 21 checks passed
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andyzhangx, mpatlasov

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants