dynamodb
dynamodb copied to clipboard
Too many require increase Lambda cold start time
Hey, first of all, thanks for your work on this module. It's a cool idea and very useful. I have been using this module and I've noticed increased Lambda cold start time simply by requiring this package. The cold start time was increased by over 500 ms so for an API it's quite high, I was wondering if it would be possible to refactor a bit and get rid of full lodash and aws-sdk require which slow things down?
https://github.com/baseprime/dynamodb/blob/master/lib/index.js#L3
Results of my tests, first one without dynamodb
{
"datapoints": 9,
"average": 235.77777777777777,
"min": 227,
"max": 247.3,
"median": 239.7,
"rawData": "227,228.4,229.7,232.7,236,239.7,240.3,240.9,247.3"
}
with dynamodb
{
"datapoints": 9,
"average": 863.5666666666666,
"min": 790.8,
"max": 925.8,
"median": 880.5,
"rawData": "790.8,828.9,836.5,861.2,867.7,880.5,880.5,900.2,925.8"
}
ColdStart time was increased from ~250ms to ~900ms
Here, a good read about cost of requiring the full aws-sdk: https://theburningmonk.com/2019/03/just-how-expensive-is-the-full-aws-sdk/
Hi @andreafalzetti Have you tried setting up a Lambda Layer with this module in it? This way your function itself gets smaller and can start in less time while the layer is only plugged with the function is ready.
@fuschini I am not sure that will help, at runtime this module requires the aws-sdk module which is loaded in memory - How is the Layer helping that? We are not talking about bundle size.
Respectfully, I thought the whole idea behind the module was the idea that it would NOT require aws-sdk as a dependency. When I tried to add it this library to my project, it now lists the aws-sdk as required. Is this a mistake? Thanks.