test(node-integration-tests): Enable Node compile cache for scenario child processes#22084
test(node-integration-tests): Enable Node compile cache for scenario child processes#22084mydea wants to merge 1 commit into
Conversation
…child processes Point every scenario child process at a shared `NODE_COMPILE_CACHE` directory so the V8 parse/compile of the `@sentry/node` + OpenTelemetry module graph — loaded from scratch by each spawned process — is cached and reused across runs. The env var is silently ignored on Node < 22, so we only set it when the parent (the same `node` binary the children run) is Node 22+, and a user-set `NODE_COMPILE_CACHE` still takes precedence. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
| ? { | ||
| ...COMPILE_CACHE_ENV, | ||
| ...process.env, |
There was a problem hiding this comment.
Bug: The code sets the NODE_COMPILE_CACHE variable but never creates the cache directory, causing Node.js to silently disable caching.
Severity: MEDIUM
Suggested Fix
Ensure the directory specified in the NODE_COMPILE_CACHE environment variable is created before any child processes that would use it are spawned. Use a method like fs.mkdirSync(cachePath, { recursive: true }) to create the directory during the runner's initialization phase.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: dev-packages/node-integration-tests/utils/runner/createRunner.ts#L422-L424
Potential issue: The code sets the `NODE_COMPILE_CACHE` environment variable to a path
for caching compiled code, but it never creates the specified directory. According to
Node.js documentation, if the directory pointed to by `NODE_COMPILE_CACHE` does not
exist when the Node process starts, caching is silently disabled. This means the
intended performance optimization will not take effect, and the feature will fail
silently without any errors or warnings. The expected performance improvement from this
change will not be realized.
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
this should be auto-created by node
|
Does not appear much faster on CI but always hard to benchmark these things... |
andreiborza
left a comment
There was a problem hiding this comment.
Hard to tell if this can lead to issues but looks good I guess 😅
Every
createRunnerscenario spawns a freshnodechild process that imports the full@sentry/node+ OpenTelemetry module graph from scratch — which is by far the dominant per-test cost (~200-300ms). This points all child processes at one sharedNODE_COMPILE_CACHEdirectory so V8 caches the parse/compile of that graph and reuses it across the thousands of child processes a test run spawns.The env var is silently ignored on Node < 22, so we gate on the parent process major version (the same
nodebinary the children run) to avoid creating an unused cache dir there. A user-setNODE_COMPILE_CACHEin the environment still takes precedence.Measured (Node 24): ~14% faster CJS child startup; ESM sees little change since
import-in-the-middledominates its loader path. No effect on Node 20 (env var ignored).🤖 Generated with Claude Code