Skip to content

Commit 4ef8aa7

Browse files
committed
fix: fsync: false when writing cache files
We're using writeFileAtomic here in order to get atomic rename, not to get full system power failure resilience. Most(tm) filesystems will guarantee either/or during a crash here, which is plenty enough for us. fsync is a nearly 3x slowdown for me, ts-jest'ing my whole codebase (~900 files in testcase).
1 parent 4a59daa commit 4ef8aa7

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- `[jest-haste-map]` [**BREAKING**] Remove `mapper` option ([#9581](https://github.com/facebook/jest/pull/9581))
88
- `[*]` Support array of paths for `moduleNameMapper` aliases ([#9465](https://github.com/facebook/jest/pull/9465))
99
- `[jest-reporters]` Adds ability to pass options to the istanbul-reporter through `coverageReporters` ([#9572](https://github.com/facebook/jest/pull/9572))
10+
- `[jest-transform]` `writeCacheFile` no longer calls `fsync` ([#9695](https://github.com/facebook/jest/pull/9695))
1011

1112
### Fixes
1213

packages/jest-transform/src/ScriptTransformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ function readCodeCacheFile(cachePath: Config.Path): string | null {
630630
*/
631631
const writeCacheFile = (cachePath: Config.Path, fileData: string) => {
632632
try {
633-
writeFileAtomic(cachePath, fileData, {encoding: 'utf8'});
633+
writeFileAtomic(cachePath, fileData, {encoding: 'utf8', fsync: false});
634634
} catch (e) {
635635
if (cacheWriteErrorSafeToIgnore(e, cachePath)) {
636636
return;

packages/jest-transform/src/__tests__/script_transformer.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ describe('ScriptTransformer', () => {
407407
expect(writeFileAtomic.sync).toBeCalledTimes(2);
408408
expect(writeFileAtomic.sync).toBeCalledWith(result.sourceMapPath, mapStr, {
409409
encoding: 'utf8',
410+
fsync: false,
410411
});
411412
});
412413

@@ -438,7 +439,7 @@ describe('ScriptTransformer', () => {
438439
expect(writeFileAtomic.sync).toBeCalledWith(
439440
result.sourceMapPath,
440441
sourceMap,
441-
{encoding: 'utf8'},
442+
{encoding: 'utf8', fsync: false},
442443
);
443444
});
444445

@@ -507,6 +508,7 @@ describe('ScriptTransformer', () => {
507508
JSON.stringify(map),
508509
{
509510
encoding: 'utf8',
511+
fsync: false,
510512
},
511513
);
512514
});
@@ -574,6 +576,7 @@ describe('ScriptTransformer', () => {
574576
JSON.stringify(instrumentedCodeMap),
575577
{
576578
encoding: 'utf8',
579+
fsync: false,
577580
},
578581
);
579582

@@ -614,6 +617,7 @@ describe('ScriptTransformer', () => {
614617
JSON.stringify(instrumentedCodeMap),
615618
{
616619
encoding: 'utf8',
620+
fsync: false,
617621
},
618622
);
619623

0 commit comments

Comments
 (0)