Does `sst` automatically do tree shaking or we wou...
# help
k
Does
sst
automatically do tree shaking or we would need to do something to enable that (TS functions)?
s
I could be wrong, but i don’t think tree-shaking matters for your stack definitions. it’s not code you’re bundling & deploying.
k
Yep that is correct what I mean is the function it bundles
s
for your Lambda code, that part’s up to you
esbuild will handle that
k
Hmm ok, so i do not use a separate esbuil config besides what sst handles by default and was wondering if it handles treeshaling by default
s
I’m not totally sure, but it should. you could always test it out & see the output of the bundle
f
Just wanted to chime in here, SST tree shakes both when building the stack definition code, and when building the function code
k
Ok awesome thanks Frank, I need to check why my cold starts are 1.4s
And it might be that mu functions are too big 😅
f
You can run
sst build
> go into the
.build/cdk.out
> you can see the package uploaded for each Lambda function.
t
@Kujtim Hoxha how big are your functions? I think I have even slower cold starts than that. Is there a reason you're concerned about cold starts?
k
@thdxr you might actually be right and it is not that important, I was just checking if I am not doing something simple and missing out on performance, 1.4s is probably totally fine and when the app is in use that won’t even matter. The size is really not big at all
344 KB
@Frank thanks
g
1.4s is a very long cold start for sure. At my current job, I use serverless framework all of our cold starts are <350ms even for functions that include Braintree for payment processing. Seems a little concerning its that high if I did want to use this even for personal projects because initial loads to every function would make the site seem really slow especially if its a site without much traffic because every function would be cold
k
@Garret Harp Any suggestion on debugging why this is the case ?
g
I'm not entirely sure how I would go about it, seeing what the output result is of the code is probably what I would look at and see if I could make any optimizations to the esbuild. I have not ever used esbuild so not sure how much you can do to optimize it.
k
Yeah you are right, I’ll dig into it a bit more
t
How are you measuring cold start? And to verify is this on a production deployment (not using sst local dev)
k
Yep it is a production deployment, I am looking at requests for a cold start vs requests from a warm start
e.x
cold start vs none cold start
Ok it is more like 1s
f
@Kujtim Hoxha any luck trying to figure out the cold start? If it’s still a myth, I’d say try striping down ur code part by part and see how cold start time changes.
k
I did exactly that and it looks like the main issue is the size of the function. When I upload the most simple function it goes down to 200ms
And I found the 2 packages that contribute the most and will have to try to replace them 😅
One of them is https://awspilot.dev/
f
Ah yeah, 200ms sounds right