-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Reduce memory usage from aws-partitions #3122
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
Conversation
….endpoint" This reverts commit 13f2c57.
gems/aws-sdk-core/lib/aws-sdk-core/plugins/regional_endpoint.rb
Outdated
Show resolved
Hide resolved
gems/aws-sdk-core/lib/aws-sdk-core/plugins/regional_endpoint.rb
Outdated
Show resolved
Hide resolved
gems/aws-sdk-core/lib/aws-sdk-core/plugins/regional_endpoint.rb
Outdated
Show resolved
Hide resolved
This reverts commit 3074fce.
…dpoint in after_initialize
gems/aws-sdk-core/lib/aws-sdk-core/plugins/regional_endpoint.rb
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. I like this approach better. Just needs some clean up I think.
build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/endpoint_parameter.rb
Show resolved
Hide resolved
build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/endpoint_parameter.rb
Outdated
Show resolved
Hide resolved
...d_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/endpoint_parameters_class.rb
Outdated
Show resolved
Hide resolved
build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/endpoints_module.rb
Outdated
Show resolved
Hide resolved
build_tools/aws-sdk-code-generator/spec/interfaces/plugins/endpoints_spec.rb
Show resolved
Hide resolved
build_tools/aws-sdk-code-generator/templates/endpoints_module.mustache
Outdated
Show resolved
Hide resolved
build_tools/aws-sdk-code-generator/templates/endpoints_plugin.mustache
Outdated
Show resolved
Hide resolved
|
||
def initialize_default_endpoint(client) | ||
client_module = Object.const_get(client.class.name.rpartition('::').first) | ||
if client.config.respond_to?(:endpoint_provider) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lot of nesting here. Can we break this up a bit with either methods and/or guard clauses?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, just rescuing exceptions cleans this up a ton.
gems/aws-sdk-core/lib/aws-sdk-core/plugins/regional_endpoint.rb
Outdated
Show resolved
Hide resolved
gems/aws-sdk-core/lib/aws-sdk-core/plugins/regional_endpoint.rb
Outdated
Show resolved
Hide resolved
build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/endpoints_module.rb
Outdated
Show resolved
Hide resolved
Detected 1 possible performance regressions:
|
This reverts commit 76412b0.
This reverts commit c1c38b4.
|
||
return nil unless binding | ||
|
||
"JMESPath.search(\"#{Underscore.underscore_jmespath(binding['path'])}\", context.params)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're wondering if context.config.simple_json
needs to be considered here to conditionally generate camel_case
or snake_case
. cc: @bquorning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried adding this patch:
diff --git i/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/endpoint_parameter.rb w/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/endpoint_parameter.rb
index 36d22c08d..aadeca202 100644
--- i/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/endpoint_parameter.rb
+++ w/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/endpoint_parameter.rb
@@ -174,7 +174,9 @@ module AwsSdkCodeGenerator
return nil unless binding
- "JMESPath.search(\"#{Underscore.underscore_jmespath(binding['path'])}\", context.params)"
+ camel_cased = binding['path']
+ snake_cased = Underscore.underscore_jmespath(binding['path'])
+ "JMESPath.search(context.config.simple_json ? \"#{camel_cased}\" : \"#{snake_cased}\", context.params)"
end
def static_context_param(operation, param_name)
Which produces the following diff (from c291968) for the generated code:
diff --git i/gems/aws-sdk-dynamodb/lib/aws-sdk-dynamodb/endpoints.rb w/gems/aws-sdk-dynamodb/lib/aws-sdk-dynamodb/endpoints.rb
index 0f9a6b7bb..41359a745 100644
--- i/gems/aws-sdk-dynamodb/lib/aws-sdk-dynamodb/endpoints.rb
+++ w/gems/aws-sdk-dynamodb/lib/aws-sdk-dynamodb/endpoints.rb
@@ -16,7 +16,7 @@ module Aws::DynamoDB
def self.build(context)
Aws::DynamoDB::EndpointParameters.create(
context.config,
- resource_arn_list: JMESPath.search("keys(request_items)", context.params),
+ resource_arn_list: JMESPath.search(context.config.simple_json ? "keys(RequestItems)" : "keys(request_items)", context.params),
)
end
end
@@ -25,7 +25,7 @@ module Aws::DynamoDB
def self.build(context)
Aws::DynamoDB::EndpointParameters.create(
context.config,
- resource_arn_list: JMESPath.search("keys(request_items)", context.params),
+ resource_arn_list: JMESPath.search(context.config.simple_json ? "keys(RequestItems)" : "keys(request_items)", context.params),
)
end
end
@@ -241,7 +241,7 @@ module Aws::DynamoDB
def self.build(context)
Aws::DynamoDB::EndpointParameters.create(
context.config,
- resource_arn: JMESPath.search("table_creation_parameters.table_name", context.params),
+ resource_arn: JMESPath.search(context.config.simple_json ? "TableCreationParameters.TableName" : "table_creation_parameters.table_name", context.params),
)
end
end
@@ -358,7 +358,7 @@ module Aws::DynamoDB
def self.build(context)
Aws::DynamoDB::EndpointParameters.create(
context.config,
- resource_arn_list: JMESPath.search("transact_items[*].get.table_name", context.params),
+ resource_arn_list: JMESPath.search(context.config.simple_json ? "TransactItems[*].Get.TableName" : "transact_items[*].get.table_name", context.params),
)
end
end
@@ -367,7 +367,7 @@ module Aws::DynamoDB
def self.build(context)
Aws::DynamoDB::EndpointParameters.create(
context.config,
- resource_arn_list: JMESPath.search("transact_items[*].[condition_check.table_name, put.table_name, delete.table_name, update.table_name][]", context.params),
+ resource_arn_list: JMESPath.search(context.config.simple_json ? "TransactItems[*].[ConditionCheck.TableName, Put.TableName, Delete.TableName, Update.TableName][]" : "transact_items[*].[condition_check.table_name, put.table_name, delete.table_name, update.table_name][]", context.params),
)
end
end
This fixes a problem we’re seeing in an internal library (which uses simple_json: true
and fails on the keys(request_items)
expressions), but I am not sure if the other changes might break things for others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should add that our problems started on v1.138.0 of the gem, after commit ce5d800.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just wondering what your use case is for simple json. I was not planning on supporting this for a new major version. If possible, I would move away from it. Can you also be specific about what bug you encountered and can you make a new issue?
The endpoints (partitions.json) loaded by aws-partitions account for a large amount of memory required when creating/using service clients and post Endpoints2.0, are required only for legacy features.
Benchmarking
code being benchmarked:
A decrease of more than 50%.
This PR does the following to reduce memory usage:
client.config.endpoint
set using an after_initailize and using the configured endpoint resolverAdditional endpoints changes:
Added a
create
class method to EndpointParameters which takes values from config. Operation endpoint parameter classes now are only generated when there is operation specific values and use thecreate
method to handle setting values from config. Example generated code for S3:Alternatives
Instead of using
define_singleton_method
to override theendpoint
method on the config struct, we could instead:client.config.endpoint
may be broken.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
To make sure we include your contribution in the release notes, please make sure to add description entry for your changes in the "unreleased changes" section of the
CHANGELOG.md
file (at corresponding gem). For the description entry, please make sure it lives in one line and starts withFeature
orIssue
in the correct format.For generated code changes, please checkout below instructions first:
https://github.com/aws/aws-sdk-ruby/blob/version-3/CONTRIBUTING.md
Thank you for your contribution!