-
Notifications
You must be signed in to change notification settings - Fork 612
Lambda Node 22 coldstart latency regression #6914
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
Comments
Hi @perpil - thanks for reporting and for your patience while I investigate. Based on my benchmarks, I was able to confirm the difference in coldstart times of ~15-20ms between Node 20 and 22. I went on to perform the benchmarks of Benchmarks
|
Thanks for the followup @aBurmeseDev I'm surprised there is such a large discrepancy between your benchmark and mine. I'm seeing very different numbers in overall initDuration (~200 ms vs ~350+ ms), code size (315K vs 2.27 MB) and delta between node 20 and 22 (50 ms vs 15-20ms). You can see my configuration here. I bundle, use esm, use 1767MB ram, arm64, remove unnecessary credentials providers, and run in Are you able to share more about your benchmark, because 50 ms on 200 is a lot more interesting than 20 ms on 350 ms and you may not be replicating what I'm reporting. If you haven't can you try running my repro? At least one other person saw the same 50 ms delta between node 20 and 22 when using the v3 javascript sdk. |
As an experiment, I decided to see what would happen if I didn't use the AWS Javascript SDK and just instantiated a http and https agent. import { Agent as hAgent, request as hRequest } from "http";
import { Agent as hsAgent, request as hsRequest } from "https";
const httpAgent = new hAgent({ keepAlive: true, maxSockets: 50 });
const httpsAgent = new hsAgent({ keepAlive: true, maxSockets: 50 });
export const handler = async (event, context) => {
return {
statusCode: 200,
body: {
requestId: context.awsRequestId,
},
};
}; On Node 20, the coldstart time is: Although some of the performance hit goes away if you only instantiate the https agent, this repro seems to point the finger at node.js or the lambda node runtime. I've reached out to the Lambda team to see if they have any thoughts on this. Update 3/26: This is a minimal repro, it's actually importing
Although there is potential to lazy load the |
Checkboxes for prior research
Describe the bug
When I updated to Node 22 on Lambda using the AWS Javascript SDK V3 last year, it added at least 50 ms to my coldstart times. For awhile I assumed it was due to the edge caches not being warm, but recently the lambda perf benchmark was updated with Node 22 and showed no appreciable difference in coldstart times between Node 20 and Node 22. I investigated further and it appears it is only when using the AWS Javascript SDK V3. In Node 22, it loads the http request bits that add 50 ms to the coldstart even if they aren't used. Similar to #6144, adding some lazy loading logic on the http request and agent should keep the coldstart performance inline with Node 20.
Regression Issue
SDK version number
@aws-sdk/client-sts 3.750
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
Node 22.11
Reproduction Steps
I've created a repro with instructions here.
Observed Behavior
Node 22 exhibits 50 additional ms of coldstart time over Node 20 in the Lambda environment.
Here is a snippet from the README in the repro:
These are samples from my runs, but the results were repeatable.
Expected Behavior
Similar coldstart performance between Node 20 and Node 22.
Possible Solution
Lazy load the http request and agent bits.
Additional Information/Context
No response
The text was updated successfully, but these errors were encountered: