Skip to content

Commit

Permalink
unreference some of the intermediate data when unserializing
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Jun 17, 2021
1 parent 273bd8f commit 3b55517
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/cache/PackFileCacheStrategy.js
Expand Up @@ -8,6 +8,7 @@
const FileSystemInfo = require("../FileSystemInfo");
const ProgressPlugin = require("../ProgressPlugin");
const { formatSize } = require("../SizeFormatHelpers");
const SerializerMiddleware = require("../serialization/SerializerMiddleware");
const LazySet = require("../util/LazySet");
const makeSerializable = require("../util/makeSerializable");
const memoize = require("../util/memoize");
Expand Down Expand Up @@ -715,6 +716,7 @@ class PackContent {
this.logger.timeEnd(timeMessage);
}
this.content = map;
this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy);
return map.get(identifier);
});
} else {
Expand All @@ -723,6 +725,7 @@ class PackContent {
this.logger.timeEnd(timeMessage);
}
this.content = map;
this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy);
return map.get(identifier);
}
}
Expand Down
19 changes: 19 additions & 0 deletions lib/serialization/SerializerMiddleware.js
Expand Up @@ -126,6 +126,25 @@ class SerializerMiddleware {
fn[LAZY_SERIALIZED_VALUE] = lazy;
return fn;
}

/**
* @param {function(): Promise<any> | any} lazy lazy function
* @returns {function(): Promise<any> | any} new lazy
*/
static unMemoizeLazy(lazy) {
if (!SerializerMiddleware.isLazy(lazy)) return lazy;
const fn = () => {
throw new Error(
"A lazy value that has been unmemorized can't be called again"
);
};
fn[LAZY_SERIALIZED_VALUE] = SerializerMiddleware.unMemoizeLazy(
lazy[LAZY_SERIALIZED_VALUE]
);
fn[LAZY_TARGET] = lazy[LAZY_TARGET];
fn.options = /** @type {any} */ (lazy).options;
return fn;
}
}

module.exports = SerializerMiddleware;

0 comments on commit 3b55517

Please sign in to comment.