Skip to content

Commit

Permalink
packager: GlobalTransformCache: cache the transform options digest
Browse files Browse the repository at this point in the history
Reviewed By: davidaurelio

Differential Revision: D4906974

fbshipit-source-id: b6cf83ba6a072400685948329070e171f65c837d
  • Loading branch information
Jean Lauliac authored and facebook-github-bot committed Apr 19, 2017
1 parent 9dc7654 commit de3478c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion packager/src/lib/GlobalTransformCache.js
Expand Up @@ -225,7 +225,7 @@ class URIBasedGlobalTransformCache {
keyOf(props: FetchProps) { keyOf(props: FetchProps) {
const hash = crypto.createHash('sha1'); const hash = crypto.createHash('sha1');
const {sourceCode, filePath, transformOptions} = props; const {sourceCode, filePath, transformOptions} = props;
this._optionsHasher.hashTransformWorkerOptions(hash, transformOptions); hash.update(this._optionsHasher.getTransformWorkerOptionsDigest(transformOptions));
const cacheKey = props.getTransformCacheKey(sourceCode, filePath, transformOptions); const cacheKey = props.getTransformCacheKey(sourceCode, filePath, transformOptions);
hash.update(JSON.stringify(cacheKey)); hash.update(JSON.stringify(cacheKey));
hash.update(crypto.createHash('sha1').update(sourceCode).digest('hex')); hash.update(crypto.createHash('sha1').update(sourceCode).digest('hex'));
Expand Down Expand Up @@ -313,9 +313,23 @@ class URIBasedGlobalTransformCache {


class OptionsHasher { class OptionsHasher {
_rootPath: string; _rootPath: string;
_cache: WeakMap<TransformWorkerOptions, string>;


constructor(rootPath: string) { constructor(rootPath: string) {
this._rootPath = rootPath; this._rootPath = rootPath;
this._cache = new WeakMap();
}

getTransformWorkerOptionsDigest(options: TransformWorkerOptions): string {
const digest = this._cache.get(options);
if (digest != null) {
return digest;
}
const hash = crypto.createHash('sha1');
this.hashTransformWorkerOptions(hash, options);
const newDigest = hash.digest('hex');
this._cache.set(options, newDigest);
return newDigest;
} }


/** /**
Expand Down
Expand Up @@ -19,12 +19,12 @@ Object {
exports[`GlobalTransformCache fetches results 1`] = ` exports[`GlobalTransformCache fetches results 1`] = `
Array [ Array [
Object { Object {
"code": "/* code from http://globalcache.com/fb94b11256237327e4eef5daa08bad33573b3781-foo.js */", "code": "/* code from http://globalcache.com/43e279be6916de8be463ef98bd72ded391608371-foo.js */",
"dependencies": Array [], "dependencies": Array [],
"dependencyOffsets": Array [], "dependencyOffsets": Array [],
}, },
Object { Object {
"code": "/* code from http://globalcache.com/b902b4a8841fcea2919c2fe9b21e68d96dff59c9-bar.js */", "code": "/* code from http://globalcache.com/e09598ad4c807cb22b32d68cfc16e0cba7fdb85c-bar.js */",
"dependencies": Array [], "dependencies": Array [],
"dependencyOffsets": Array [], "dependencyOffsets": Array [],
}, },
Expand Down

0 comments on commit de3478c

Please sign in to comment.