Repository navigation
Reduce Node Lambda cold-start overhead with synchronous ESM loader hooks - #846
Draft
lucaspimentel wants to merge 3 commits into
Draft
lucaspimentel wants to merge 3 commits into
lucaspimentel wants to merge 3 commits into
Conversation
… Lambda cold start time On Lambda's Node runtime, the tracer's ESM instrumentation hooks were installed through a background loader thread, because the runtime launches Node with require(esm) disabled. Each module load then paid synchronous round-trips to that thread, adding roughly 60 ms to cold-start init in local measurements with the AWS Runtime Interface Emulator. The hooks are now installed in-thread on Node versions that support it (22.22.3+, 24.11.1+, 25.1+, 26+). If in-thread installation fails partway, the background loader is not also installed, since a second registration would run the ESM instrumentation twice on every module. Older Node versions keep the previous behavior.
This comment has been minimized.
This comment has been minimized.
Member
Author
|
@DataDog review |
There was a problem hiding this comment.
More details
The registration paths preserve hook installation before handler loading, including asynchronous fallback when synchronous hooks are unavailable. The completed static review found no reportable regression.
🤖 Bits Code Review · Commit f1bf76b · @DataDog review to ask questions
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Install dd-trace's ESM instrumentation hooks in-thread on supported Node versions instead of starting a background loader worker during Lambda initialization.
import(), then register its synchronous hooks before loading the user handler.Motivation
The ESM loader registration added in #801 (layer v12.142.0) increased Node Lambda cold-start overhead. #819 (v12.143.0) reduced that overhead, but the Lambda bootstrap still launches Node with
--no-experimental-require-moduleby default. This prevents dd-trace's registration entry point from reaching its synchronous hooks throughrequire(esm), so it falls back to the background loader worker.Dynamic
import()is unaffected by that flag and allows the synchronous hooks to be installed directly.A local AWS Lambda RIE benchmark of the committed change, using Node 24.21.0 and dd-trace 6.15.0, showed:
Both variants used the same layer and fixtures, with fresh containers and interleaved, alternating run order. These are local RIE/WSL measurements, not deployed Lambda latency estimates. The ESM fixture's 100 ms top-level-await delay was unchanged.
Testing Guidelines
--runInBand.--no-experimental-require-module, while preserving durable execution spans.git diff --checkpass.Additional Notes
Types of Changes
Check all that apply