Repository navigation
Conversation
The transformed-code cache file is only ever read back when `config.cache` is true, so writing it under `--no-cache` / `cache: false` costs an atomic write (write + rename) per transformed module for nothing. Source maps are still written: stack-trace remapping and coverage read them back by path.
✅ Deploy Preview for jestjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
babel-jest
babel-plugin-jest-hoist
babel-preset-jest
create-jest
@jest/diff-sequences
expect
@jest/expect-utils
jest
jest-changed-files
jest-circus
jest-cli
jest-config
@jest/console
@jest/core
@jest/create-cache-key-function
jest-diff
jest-docblock
jest-each
@jest/environment
jest-environment-jsdom
@jest/environment-jsdom-abstract
jest-environment-node
@jest/expect
@jest/fake-timers
@jest/get-type
@jest/globals
jest-haste-map
jest-jasmine2
jest-leak-detector
jest-matcher-utils
jest-message-util
jest-mock
@jest/pattern
jest-phabricator
jest-regex-util
@jest/reporters
jest-resolve
jest-resolve-dependencies
jest-runner
jest-runtime
@jest/schemas
jest-snapshot
@jest/snapshot-utils
@jest/source-map
@jest/test-result
@jest/test-sequencer
@jest/transform
@jest/types
jest-util
jest-validate
jest-watcher
jest-worker
pretty-format
commit: |
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.
Summary
ScriptTransformerwrites the transformed code tocacheDirectoryfor every module it transforms, even whencacheisfalse(--no-cache). That file is only ever read back behindthis._config.cache(bothreadCodeCacheFilecall sites), so with the cache off, each write is thrown away. Skipping it avoids one atomic write per transformed module: a temp-file write plus arename, fromwrite-file-atomic.This change guards the single
writeCodeCacheFilecall withthis._config.cache. Nothing else changes:sourceMapPathis returned to callers and read back by path for stack-trace remapping and coverage, regardless ofcache.cache: true(the default) behaves exactly as before. Same reads, same writes, same keys.Why it matters
The general point: writing a file that will never be read is pure overhead. It costs filesystem syscalls, disk I/O and cache-directory churn, and grows with the number of modules a test run transforms.
It matters more in sandboxed or hermetic runners, where
cache: falseis the norm rather than an escape hatch. For example,aspect_rules_jestfor Bazel setsconfig.cache = falseand pointscacheDirectoryat the test's freshTEST_TMPDIR, because a transform cache cannot be shared across hermetic test actions. There, every Jest shard pays for one throwaway write per transformed module on every run. Sandbox filesystems (symlink trees, FUSE, network-backed temp dirs) tend to make those small writes and renames more expensive than on a plain local disk.Benchmarks
All numbers are wall-clock medians of interleaved runs. The order alternates each round, the same checkout is used for both sides, and only this change differs (
@jest/transform/buildswapped betweenmainand this branch). macOS, Apple M-series, Node 26.Minimal repro (1,531 small ES modules, 8 test files,
babel-jest,jest --no-cachewith a fresh--cacheDirectory, 6 runs per side):main--runInBand--maxWorkers=4A large private repo (a 403-test slice,
@swc/jest, 5 runs per side):mainjest --no-cache, fresh cache dir, 3 workersaspect_rules_jest, sandboxed,cache: false), JestTime:In every configuration, this PR was faster in every interleaved pair, and the min/max ranges do not overlap. Test results were identical.
Minimal repro setup
With
babel-jest+@babel/plugin-transform-modules-commonjs(sourceMaps: 'both'), runrm -rf cc && jest --no-cache --cacheDirectory=cc, then count the files undercc/jest-transform-cache-*(*.mapvs the rest).Test plan
cache: false; they now also assert that it is not written (writeFileAtomic.syncnot called with the code-cache path), where before they asserted that some write happened.writes only the source map when \config.cache` is false`: with a transformer that returns a map, exactly one write happens, and it is the source map.packages/jest-transformpass:--no-cache, pluscoverageRemapping,stackTrace,transformandclearCache(29 suites; this covers V8/babel coverage and source-mapped stack traces under--no-cache):yarn build,yarn typecheck:tests,yarn eslintandyarn prettier --checkon the changed files, andyarn check-copyright-headers: all pass.— sent via Glean Tau