Skip to content

Commit

Permalink
Revert "Cache result of endpoint partitioning"
Browse files Browse the repository at this point in the history
This reverts commit 8cf672b.
  • Loading branch information
jdisanti committed Nov 29, 2023
1 parent 8cf672b commit 199b30d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package software.amazon.smithy.rust.codegen.client.smithy.endpoint.rulesgen
import software.amazon.smithy.model.node.Node
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.endpointsLib
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.generators.CustomRuntimeFunction
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.generators.EndpointStdLib
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
import software.amazon.smithy.rust.codegen.core.rustlang.rust
Expand Down Expand Up @@ -72,25 +71,13 @@ class AwsPartitionResolver(runtimeConfig: RuntimeConfig, private val partitionsD
CargoDependency.Regex,
).toType()
.resolve("PartitionResolver"),
"Lazy" to CargoDependency.OnceCell.toType().resolve("sync::Lazy"),
)

override fun structFieldInit() = writable {
val json = Node.printJson(partitionsDotJson).dq()
rustTemplate(
"""partition_resolver: #{DEFAULT_PARTITION_RESOLVER}.clone()""",
"""partition_resolver: #{PartitionResolver}::new_from_json(b$json).expect("valid JSON")""",
*codegenScope,
"DEFAULT_PARTITION_RESOLVER" to RuntimeType.forInlineFun("DEFAULT_PARTITION_RESOLVER", EndpointStdLib) {
rustTemplate(
"""
// Loading the partition JSON is expensive since it involves many regex compilations,
// so cache the result so that it only need to be paid for the first constructed client.
pub(crate) static DEFAULT_PARTITION_RESOLVER: #{Lazy}<#{PartitionResolver}> =
#{Lazy}::new(|| #{PartitionResolver}::new_from_json(b$json).expect("valid JSON"));
""",
*codegenScope,
)
},
)
}

Expand Down
8 changes: 4 additions & 4 deletions rust-runtime/inlineable/src/endpoint_lib/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::borrow::Cow;
use std::collections::HashMap;

/// Determine the AWS partition metadata for a given region
#[derive(Clone, Debug, Default)]
#[derive(Debug, Default)]
pub(crate) struct PartitionResolver {
partitions: Vec<PartitionMetadata>,
}
Expand Down Expand Up @@ -151,7 +151,7 @@ impl PartitionResolver {

type Str = Cow<'static, str>;

#[derive(Clone, Debug)]
#[derive(Debug)]
pub(crate) struct PartitionMetadata {
id: Str,
region_regex: Regex,
Expand Down Expand Up @@ -204,7 +204,7 @@ impl PartitionMetadata {
}
}

#[derive(Clone, Debug)]
#[derive(Debug)]
pub(crate) struct PartitionOutput {
name: Str,
dns_suffix: Str,
Expand All @@ -213,7 +213,7 @@ pub(crate) struct PartitionOutput {
supports_dual_stack: bool,
}

#[derive(Clone, Debug, Default)]
#[derive(Debug, Default)]
pub(crate) struct PartitionOutputOverride {
name: Option<Str>,
dns_suffix: Option<Str>,
Expand Down

0 comments on commit 199b30d

Please sign in to comment.