From 172deff731fd0254969a4ca06f7bc4011235202d Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sun, 13 Jul 2025 01:38:00 -0700 Subject: [PATCH] Use new `hints.mostly-unused` to speed up compilation Most users of the AWS SDK crates will use a fraction of their API surface area. Nightly rustc now provides an option `-Zhint-mostly-unused` to tell it to defer as much compilation as possible, which provides a substantial performance improvement if most of that compilation doesn't end up happening. Cargo plumbs this option through using the new `[hints]` table. This will cause users of the AWS SDK crates to default to setting `hint-mostly-unused`. (Top-level crates can override this if they wish, using a new profile option.) Note that setting this hint does not increase the MSRV of the AWS SDK crates, as old versions of Cargo will ignore it. New versions of Cargo will respect it automatically (and, until we stabilize it, Cargo will do nothing unless you pass `-Zprofile-hint-mostly-unused` to cargo). Some sample performance numbers: this takes `aws-sdk-ec2` compilation time ~4m07s to ~2m04s, a ~50% speedup. --- .changelog/hint-mostly-unused.md | 11 +++++++++++ aws/sdk/build.gradle.kts | 1 + .../rust/codegen/client/smithy/ClientRustSettings.kt | 3 +++ .../rust/codegen/client/testutil/TestHelpers.kt | 2 ++ .../rust/codegen/core/smithy/CoreRustSettings.kt | 4 ++++ .../core/smithy/generators/CargoTomlGenerator.kt | 3 +++ .../amazon/smithy/rust/codegen/core/testutil/Rust.kt | 1 + .../smithy/rust/codegen/core/testutil/TestHelpers.kt | 2 ++ .../rust/codegen/server/smithy/ServerRustSettings.kt | 3 +++ .../server/smithy/testutil/ServerTestHelpers.kt | 2 ++ 10 files changed, 32 insertions(+) create mode 100644 .changelog/hint-mostly-unused.md diff --git a/.changelog/hint-mostly-unused.md b/.changelog/hint-mostly-unused.md new file mode 100644 index 00000000000..a77d16b0bc8 --- /dev/null +++ b/.changelog/hint-mostly-unused.md @@ -0,0 +1,11 @@ +--- +applies_to: ["client", "aws-sdk-rust"] +authors: ["joshtriplett"] +references: [] +breaking: false +new_feature: true +bug_fix: false +--- +Use new `hints.mostly-unused` in Cargo to speed up compilation, given that most +users of the AWS SDK crates will use a fraction of their API surface area. This +speeds up compilation of `aws-sdk-ec2` from ~4m07s to ~2m04s, a ~50% speedup. diff --git a/aws/sdk/build.gradle.kts b/aws/sdk/build.gradle.kts index e41947a82e2..3630cd494a6 100644 --- a/aws/sdk/build.gradle.kts +++ b/aws/sdk/build.gradle.kts @@ -118,6 +118,7 @@ fun generateSmithyBuild(services: AwsServices): String { "moduleRepository": "https://github.com/awslabs/aws-sdk-rust", "license": "Apache-2.0", "minimumSupportedRustVersion": "${getRustMSRV()}", + "hintMostlyUnused": true, "customizationConfig": { "awsSdk": { "awsSdkBuild": true, diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustSettings.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustSettings.kt index 6ef6cc5433f..47a64dfe966 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustSettings.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustSettings.kt @@ -37,6 +37,7 @@ data class ClientRustSettings( override val license: String?, override val examplesUri: String?, override val minimumSupportedRustVersion: String? = null, + override val hintMostlyUnused: Boolean = true, override val customizationConfig: ObjectNode?, ) : CoreRustSettings( service, @@ -50,6 +51,7 @@ data class ClientRustSettings( license, examplesUri, minimumSupportedRustVersion, + hintMostlyUnused, customizationConfig, ) { companion object { @@ -72,6 +74,7 @@ data class ClientRustSettings( license = coreRustSettings.license, examplesUri = coreRustSettings.examplesUri, minimumSupportedRustVersion = coreRustSettings.minimumSupportedRustVersion, + hintMostlyUnused = coreRustSettings.hintMostlyUnused, customizationConfig = coreRustSettings.customizationConfig, ) } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt index b087d5078e4..c20cf09af51 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt @@ -37,6 +37,7 @@ fun testClientRustSettings( license: String? = null, examplesUri: String? = null, minimumSupportedRustVersion: String? = null, + hintMostlyUnused: Boolean = false, customizationConfig: ObjectNode? = null, ) = ClientRustSettings( service, @@ -50,6 +51,7 @@ fun testClientRustSettings( license, examplesUri, minimumSupportedRustVersion, + hintMostlyUnused, customizationConfig, ) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CoreRustSettings.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CoreRustSettings.kt index e320540b0de..a5bb8f6da76 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CoreRustSettings.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CoreRustSettings.kt @@ -27,6 +27,7 @@ private const val RUNTIME_CONFIG = "runtimeConfig" private const val LICENSE = "license" private const val EXAMPLES = "examples" private const val MINIMUM_SUPPORTED_RUST_VERSION = "minimumSupportedRustVersion" +private const val HINT_MOSTLY_UNUSED = "hintMostlyUnused" private const val CUSTOMIZATION_CONFIG = "customizationConfig" const val CODEGEN_SETTINGS = "codegen" @@ -90,6 +91,7 @@ open class CoreRustSettings( open val license: String?, open val examplesUri: String? = null, open val minimumSupportedRustVersion: String? = null, + open val hintMostlyUnused: Boolean = false, open val customizationConfig: ObjectNode? = null, ) { /** @@ -179,6 +181,7 @@ open class CoreRustSettings( EXAMPLES, LICENSE, MINIMUM_SUPPORTED_RUST_VERSION, + HINT_MOSTLY_UNUSED, CUSTOMIZATION_CONFIG, ), ) @@ -201,6 +204,7 @@ open class CoreRustSettings( license = config.getStringMember(LICENSE).orNull()?.value, examplesUri = config.getStringMember(EXAMPLES).orNull()?.value, minimumSupportedRustVersion = config.getStringMember(MINIMUM_SUPPORTED_RUST_VERSION).orNull()?.value, + hintMostlyUnused = config.getBooleanMemberOrDefault(HINT_MOSTLY_UNUSED, false), customizationConfig = config.getObjectMember(CUSTOMIZATION_CONFIG).orNull(), ) } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt index e5f49163489..3ddb2381f98 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt @@ -50,6 +50,7 @@ class CargoTomlGenerator( private val moduleLicense: String?, private val moduleRepository: String?, private val minimumSupportedRustVersion: String?, + private val hintMostlyUnused: Boolean, private val writer: RustWriter, private val manifestCustomizations: ManifestCustomizations = emptyMap(), private val dependencies: List = emptyList(), @@ -69,6 +70,7 @@ class CargoTomlGenerator( settings.license, settings.moduleRepository, settings.minimumSupportedRustVersion, + settings.hintMostlyUnused, writer, manifestCustomizations, dependencies, @@ -101,6 +103,7 @@ class CargoTomlGenerator( ).toMap(), ).toMap(), ).toMap(), + hintMostlyUnused.let { "hints" to listOfNotNull("mostly-unused" to true).toMap() }, "dependencies" to dependencies.filter { it.scope == DependencyScope.Compile } .associate { it.name to it.toMap() }, diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index 368081e7643..f64fa377538 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -488,6 +488,7 @@ private fun String.intoCrate( moduleLicense = null, moduleRepository = null, minimumSupportedRustVersion = null, + hintMostlyUnused = false, writer = this, dependencies = deps, ).render() diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt index 42997a80127..28658827b65 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt @@ -127,6 +127,7 @@ fun testRustSettings( moduleAuthors: List = listOf("notrelevant"), moduleDescription: String = "not relevant", moduleRepository: String? = null, + hintMostlyUnused: Boolean = false, runtimeConfig: RuntimeConfig = TestRuntimeConfig, codegenConfig: CoreCodegenConfig = CoreCodegenConfig(), license: String? = null, @@ -138,6 +139,7 @@ fun testRustSettings( moduleAuthors, moduleDescription, moduleRepository, + hintMostlyUnused, runtimeConfig, codegenConfig, license, diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRustSettings.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRustSettings.kt index b5949ad09c7..3c8c57b7b1d 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRustSettings.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRustSettings.kt @@ -39,6 +39,7 @@ data class ServerRustSettings( override val license: String?, override val examplesUri: String?, override val minimumSupportedRustVersion: String? = null, + override val hintMostlyUnused: Boolean = false, override val customizationConfig: ObjectNode?, ) : CoreRustSettings( service, @@ -52,6 +53,7 @@ data class ServerRustSettings( license, examplesUri, minimumSupportedRustVersion, + hintMostlyUnused, customizationConfig, ) { companion object { @@ -74,6 +76,7 @@ data class ServerRustSettings( license = coreRustSettings.license, examplesUri = coreRustSettings.examplesUri, minimumSupportedRustVersion = coreRustSettings.minimumSupportedRustVersion, + hintMostlyUnused = coreRustSettings.hintMostlyUnused, customizationConfig = coreRustSettings.customizationConfig, ) } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt index a03dfbdd4e3..77cd8368cf1 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt @@ -82,6 +82,7 @@ fun serverTestRustSettings( license: String? = null, examplesUri: String? = null, minimumSupportedRustVersion: String? = null, + hintMostlyUnused: Boolean = false, customizationConfig: ObjectNode? = null, ) = ServerRustSettings( service, @@ -95,6 +96,7 @@ fun serverTestRustSettings( license, examplesUri, minimumSupportedRustVersion, + hintMostlyUnused, customizationConfig, )