Skip to content

Use new hints.mostly-unused to speed up compilation #4208

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changelog/hint-mostly-unused.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions aws/sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -50,6 +51,7 @@ data class ClientRustSettings(
license,
examplesUri,
minimumSupportedRustVersion,
hintMostlyUnused,
customizationConfig,
) {
companion object {
Expand All @@ -72,6 +74,7 @@ data class ClientRustSettings(
license = coreRustSettings.license,
examplesUri = coreRustSettings.examplesUri,
minimumSupportedRustVersion = coreRustSettings.minimumSupportedRustVersion,
hintMostlyUnused = coreRustSettings.hintMostlyUnused,
customizationConfig = coreRustSettings.customizationConfig,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fun testClientRustSettings(
license: String? = null,
examplesUri: String? = null,
minimumSupportedRustVersion: String? = null,
hintMostlyUnused: Boolean = false,
customizationConfig: ObjectNode? = null,
) = ClientRustSettings(
service,
Expand All @@ -50,6 +51,7 @@ fun testClientRustSettings(
license,
examplesUri,
minimumSupportedRustVersion,
hintMostlyUnused,
customizationConfig,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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,
) {
/**
Expand Down Expand Up @@ -179,6 +181,7 @@ open class CoreRustSettings(
EXAMPLES,
LICENSE,
MINIMUM_SUPPORTED_RUST_VERSION,
HINT_MOSTLY_UNUSED,
CUSTOMIZATION_CONFIG,
),
)
Expand All @@ -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(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CargoDependency> = emptyList(),
Expand All @@ -69,6 +70,7 @@ class CargoTomlGenerator(
settings.license,
settings.moduleRepository,
settings.minimumSupportedRustVersion,
settings.hintMostlyUnused,
writer,
manifestCustomizations,
dependencies,
Expand Down Expand Up @@ -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() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ private fun String.intoCrate(
moduleLicense = null,
moduleRepository = null,
minimumSupportedRustVersion = null,
hintMostlyUnused = false,
writer = this,
dependencies = deps,
).render()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ fun testRustSettings(
moduleAuthors: List<String> = listOf("notrelevant"),
moduleDescription: String = "not relevant",
moduleRepository: String? = null,
hintMostlyUnused: Boolean = false,
runtimeConfig: RuntimeConfig = TestRuntimeConfig,
codegenConfig: CoreCodegenConfig = CoreCodegenConfig(),
license: String? = null,
Expand All @@ -138,6 +139,7 @@ fun testRustSettings(
moduleAuthors,
moduleDescription,
moduleRepository,
hintMostlyUnused,
Copy link
Contributor

Choose a reason for hiding this comment

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

order here appears off

Copy link
Contributor

Choose a reason for hiding this comment

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

ought to be something like

    ...
    license,
    examplesUri,
    minimumSupportedRustVersion = null,
    hintMostlyUnused,
)

runtimeConfig,
codegenConfig,
license,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -52,6 +53,7 @@ data class ServerRustSettings(
license,
examplesUri,
minimumSupportedRustVersion,
hintMostlyUnused,
customizationConfig,
) {
companion object {
Expand All @@ -74,6 +76,7 @@ data class ServerRustSettings(
license = coreRustSettings.license,
examplesUri = coreRustSettings.examplesUri,
minimumSupportedRustVersion = coreRustSettings.minimumSupportedRustVersion,
hintMostlyUnused = coreRustSettings.hintMostlyUnused,
customizationConfig = coreRustSettings.customizationConfig,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ fun serverTestRustSettings(
license: String? = null,
examplesUri: String? = null,
minimumSupportedRustVersion: String? = null,
hintMostlyUnused: Boolean = false,
customizationConfig: ObjectNode? = null,
) = ServerRustSettings(
service,
Expand All @@ -95,6 +96,7 @@ fun serverTestRustSettings(
license,
examplesUri,
minimumSupportedRustVersion,
hintMostlyUnused,
customizationConfig,
)

Expand Down
Loading