-
Notifications
You must be signed in to change notification settings - Fork 811
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
Initializing GeneratedServiceMetadataProvider takes a while #3664
Comments
Hi @awmcc90 thank you for the thorough report! We recently changed to a use As to the endpoint provider issue, it seems like a bug, could you create a new issue for it? |
Thanks for your reply. I'm not sure I'm the right person to make the ticket about the Also, while looking into this I noticed that some of the codegen results in dead code. One example of that is this line in |
Yeah, we are planning to make the change to remove the usage of
Good catch, could you create a ticket for it? |
Beyond being slow, this also allocates ~10MB based on a test with async-profiler. If none of this data is ever retrieved, then this is very wasteful, creating a spike of memory allocation. |
Any update on this? I made a PR but that's way out of sync at this point. |
Describe the feature
When creating a service client (e.g. DynamoDbAsyncClient) there is an expensive one time call to create
GeneratedServiceMetadataProvider
which incurs the penalty of an expensive static initializer. The static initializer creates a map object with 299 entries (currently), each of which also initializes an instance that extendsServiceMetadata
which also all have large static initialization overhead.From the looks of it, every single instance of
ServiceMetadata
is initialized but in my use case, onlyDynamodbServiceMetadata
was needed. And this call was only needed to acquire the client endpoint.I profiled just the cold start initialization of
GeneratedServiceMetadataProvider
to confirm my suspicions and get a general idea of the overhead incurred. On my machine the operation took between 350 and 500 ms. I think this could be improved significantly by implementing lazy loading ofServiceMetadata
objects.Benchmark
Results:
Use Case
The goal is to reduce the overhead as much as possible and make cold start times as performant as they can be. This is an ongoing process that a number of other tickets are related to. In fact the ticket that lead to the creation of the
GeneratedServiceMetadataProvider
class was done so in an effort to reduce cold start times of theDynamoDbClient
.Proposed Solution
Lazily initialize the
GeneratedServiceMetadataProvider
using a static factory method. I created a proof of concept to test a possible improvement to the object initialization.This produced the following results using the same benchmark as above:
About a 25x improvement in object creation speed, not to mention the memory overhead thats saved by deferring initialization of all the other
ServiceMetadata
instances that aren't needed.Other Information
As an aside, I was surprised that providing an
EndpointProvider
to the client builder - one which doesn't go throughGeneratedServiceMetadataProvider
- wasn't used at all when setting the endpoint of the client on creation. Why wouldn't the client builder use the endpoint provider, if present, if it's going to use the provider for every request anyway?Related issues:
#748
#6
Acknowledgements
AWS Java SDK version used
2
JDK version used
1.8
Operating System and version
macOS Monterey 12.6.1
The text was updated successfully, but these errors were encountered: