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

pessimize pluto and cfsignal builds #3892

Merged
merged 1 commit into from
Apr 12, 2024

Conversation

bcressey
Copy link
Contributor

Issue number:
N/A

Description of changes:
On a high-end build machine, pluto takes 12 minutes to compile when using one codegen unit, and around 3 minutes to compile with the default of 16 codegen units. This is because the aws-sdk-ec2 crate contains a massive amount of code.

Sacrifice a little code quality and spec file clarity to bring build times for this package back under control by setting up a new target directory and another background job for pluto. cfsignal is given the same treatment, even though aws-sdk-cloudformation is not as much of a problem, because they share crate dependencies that aren't used by other crates.

Refactor the handling of stdout and stderr file descriptors to ensure that the cargo build invocation is shown when printing the results, instead of when the job is first started. Otherwise, it overlaps with the non-static, non-AWS-SDK output in a confusing way.

Testing done:
Built vmware-dev, aws-dev, aws-k8s-1.28 to confirm that the expected binaries were built.

Launched the aws-k8s-1.28 node which joined the cluster after pluto generated the usual settings.

Binary size before this change:

bash-5.1# ls -latr /usr/bin/pluto /usr/bin/cfsignal
-rwxr-xr-x. 1 root root  8903560 Apr  5 22:52 /usr/bin/cfsignal
-rwxr-xr-x. 1 root root 12931096 Apr  5 22:52 /usr/bin/pluto

Binary size after this change:

bash-5.1# ls -latr /usr/bin/pluto /usr/bin/cfsignal
-rwxr-xr-x. 1 root root 11617128 Apr 11 22:48 /usr/bin/cfsignal
-rwxr-xr-x. 1 root root 17133856 Apr 11 22:48 /usr/bin/pluto

Definitely worse, but acceptable if this improves build times as expected.

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

@bcressey bcressey requested review from jpculp and webern April 11, 2024 23:52
@bcressey bcressey marked this pull request as ready for review April 12, 2024 00:27
# Save the PID so we can wait for it later.
static_pid="$!"
exec 1>&3 2>&4

%if %{with aws_platform} || %{with aws_k8s_family}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this one of those few exceptions where it is OK to make the spec file platform or family-aware?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this one of those few exceptions where it is OK to make the spec file platform or family-aware?

This is just to keep the existing conditional compile logic in effect.

When these crates don't need to be conditionally compiled any more, we can just drop the conditions and always do the AWS SDK consumer crates in a separate pass (like we do with static builds).

exec 3>&1 4>&2
aws_sdk_output="$(mktemp)"
exec 1>"${aws_sdk_output}" 2>&1
RUSTFLAGS="$(echo "%{__global_rustflags_shared}" | sed -e 's,-Ccodegen-units=1,,g')" \
Copy link
Contributor

Choose a reason for hiding this comment

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

Just for my own understanding, what's the penalty of building all the first-party crates with more than one code unit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just for my own understanding, what's the penalty of building all the first-party crates with more than one code unit?

I expect it'd be in the realm of 10-20% binary size increase and an unknown performance hit. It'd push us pretty close to the current filesystem size limit for existing variants.

# Store the output so we can print it after waiting for the backgrounded job.
exec 3>&1 4>&2
Copy link
Member

Choose a reason for hiding this comment

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

nit: a comment explaining the purpose (line 330) of fd 3 and fd 4 here would have helped me out. I experienced seconds and seconds of bemusement, tbh ("fd 3: what? Non-standard-wrong-error with bonus Hadamard matrix?"). Live and learn. This may just be me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nit: a comment explaining the purpose (line 330) of fd 3 and fd 4 here would have helped me out.

Added a comment before the file descriptor juggling starts to explain what's going on.

Copy link
Member

@larvacea larvacea left a comment

Choose a reason for hiding this comment

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

Looks good to me.

On a high-end build machine, `pluto` takes 12 minutes to compile when
using one codegen unit, and around 3 minutes to compile with the
default of 16 codegen units. This is because the aws-sdk-ec2 crate
contains a massive amount of code.

Sacrifice a little code quality and spec file clarity to bring build
times for this package back under control by setting up a new target
directory and another background job for `pluto`. `cfsignal` is given
the same treatment, even though aws-sdk-cloudformation is not as much
of a problem, because they share crate dependencies that aren't used
by other crates.

Refactor the handling of stdout and stderr file descriptors to ensure
that the `cargo build` invocation is shown when printing the results,
instead of when the job is first started. Otherwise, it overlaps with
the non-static, non-AWS-SDK output in a confusing way.

Signed-off-by: Ben Cressey <bcressey@amazon.com>
Copy link
Member

@larvacea larvacea left a comment

Choose a reason for hiding this comment

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

Thanks!

@bcressey bcressey merged commit ed0f6aa into bottlerocket-os:develop Apr 12, 2024
35 checks passed
@bcressey bcressey deleted the oh-pluto branch April 12, 2024 20:24
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.

None yet

4 participants