Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(middleware-user-agent): cache user agent string
Cache the user agent string after the first successful computation. Do this in a way that ensures `await` isn't called in the middleware if the user agent is already computed (run middleware in single tick). Middleware such as the user agent is called on every single call to aws, so for dbs (e.g. fetching single keys), the middleware should in principle be memory/cpu efficient. Context: I saw that client-dynamodb calls took twice as long to resolve, and cpu usage was slightly higher after switching from aws-sdk, even after the fix for 2223. The impact on dynamodb promise resolution times was higher at peak load when Node.js was using more cpu per process. (The Node.js process had around 40% cpu usage) - I'm not completely certain this is the cause, but it seems related. There's extra function calls, map, array creation/join, and string escaping. Additionally, the call to await() would spread out the work of creating the user agent across multiple CPU ticks. - (Related to 2027 which was fixed by memoizing in the implementation of defaultUserAgentProvider) Avoid extra cpu from calling map, defaultUserAgentProvider+await, etc. As a result of 388b180 switching from defaultUserAgent to defaultUserAgentProvider, the middleware would have to recompute the user agent on every single api call. This fixes that by computing the user agent only once, when the middleware is instantiated. (So creating a client but not using it will now call this, but creating a client has overhead anyway)
- Loading branch information