Skip to content

Commit 1f6c4e9

Browse files
perf: use sha1 instead of sha256 for hashing (#13421)
1 parent 55c5536 commit 1f6c4e9

File tree

8 files changed

+14
-12
lines changed

8 files changed

+14
-12
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### Performance
1010

11+
- `[*]` Use sha1 instead of sha256 for hashing [#13421](https://github.com/facebook/jest/pull/13421)
12+
1113
## 29.2.0
1214

1315
### Features

packages/babel-jest/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function getCacheKeyFromConfig(
7878

7979
const configPath = [babelOptions.config ?? '', babelOptions.babelrc ?? ''];
8080

81-
return createHash('sha256')
81+
return createHash('sha1')
8282
.update(THIS_FILE)
8383
.update('\0', 'utf8')
8484
.update(JSON.stringify(babelOptions.options))

packages/jest-circus/src/__mocks__/testUtils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface Result extends ExecaSyncReturnValue {
3131
}
3232

3333
export const runTest = (source: string) => {
34-
const filename = createHash('sha256')
34+
const filename = createHash('sha1')
3535
.update(source)
3636
.digest('hex')
3737
.substring(0, 32);

packages/jest-config/src/__tests__/normalize.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ afterEach(() => {
7272

7373
it('picks an id based on the rootDir', async () => {
7474
const rootDir = '/root/path/foo';
75-
const expected = createHash('sha256')
75+
const expected = createHash('sha1')
7676
.update('/root/path/foo')
7777
.update(String(Infinity))
7878
.digest('hex')

packages/jest-config/src/normalize.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ const normalizeMissingOptions = (
301301
projectIndex: number,
302302
): Config.InitialOptionsWithRootDir => {
303303
if (!options.id) {
304-
options.id = createHash('sha256')
304+
options.id = createHash('sha1')
305305
.update(options.rootDir)
306306
// In case we load config from some path that has the same root dir
307307
.update(configPath || '')

packages/jest-create-cache-key-function/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function getGlobalCacheKey(files: Array<string>, values: Array<string>) {
4949
]
5050
.reduce(
5151
(hash, chunk) => hash.update('\0', 'utf8').update(chunk || ''),
52-
createHash('sha256'),
52+
createHash('sha1'),
5353
)
5454
.digest('hex')
5555
.substring(0, 32);
@@ -62,7 +62,7 @@ function getCacheKeyFunction(globalCacheKey: string): GetCacheKeyFunction {
6262
const inferredOptions = options || configString;
6363
const {config, instrument} = inferredOptions;
6464

65-
return createHash('sha256')
65+
return createHash('sha1')
6666
.update(globalCacheKey)
6767
.update('\0', 'utf8')
6868
.update(sourceText)

packages/jest-haste-map/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class HasteMap extends EventEmitter implements IHasteMap {
295295
}
296296

297297
private async setupCachePath(options: Options): Promise<void> {
298-
const rootDirHash = createHash('sha256')
298+
const rootDirHash = createHash('sha1')
299299
.update(options.rootDir)
300300
.digest('hex')
301301
.substring(0, 32);
@@ -344,7 +344,7 @@ class HasteMap extends EventEmitter implements IHasteMap {
344344
id: string,
345345
...extra: Array<string>
346346
): string {
347-
const hash = createHash('sha256').update(extra.join(''));
347+
const hash = createHash('sha1').update(extra.join(''));
348348
return path.join(
349349
tmpdir,
350350
`${id.replace(/\W/g, '-')}-${hash.digest('hex').substring(0, 32)}`,

packages/jest-transform/src/ScriptTransformer.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ class ScriptTransformer {
117117
transformerCacheKey: string | undefined,
118118
): string {
119119
if (transformerCacheKey != null) {
120-
return createHash('sha256')
120+
return createHash('sha1')
121121
.update(transformerCacheKey)
122122
.update(CACHE_VERSION)
123123
.digest('hex')
124124
.substring(0, 32);
125125
}
126126

127-
return createHash('sha256')
127+
return createHash('sha1')
128128
.update(fileData)
129129
.update(transformOptions.configString)
130130
.update(transformOptions.instrument ? 'instrument' : '')
@@ -882,7 +882,7 @@ const stripShebang = (content: string) => {
882882
* could get corrupted, out-of-sync, etc.
883883
*/
884884
function writeCodeCacheFile(cachePath: string, code: string) {
885-
const checksum = createHash('sha256')
885+
const checksum = createHash('sha1')
886886
.update(code)
887887
.digest('hex')
888888
.substring(0, 32);
@@ -901,7 +901,7 @@ function readCodeCacheFile(cachePath: string): string | null {
901901
return null;
902902
}
903903
const code = content.substring(33);
904-
const checksum = createHash('sha256')
904+
const checksum = createHash('sha1')
905905
.update(code)
906906
.digest('hex')
907907
.substring(0, 32);

0 commit comments

Comments
 (0)