Skip to content

Commit

Permalink
Reduce memory footprint of storing fs erros in cache
Browse files Browse the repository at this point in the history
  • Loading branch information
shYkiSto committed Aug 18, 2023
1 parent 3a28f47 commit 5fa0bdf
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/CachedInputFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,19 @@ class CacheBackend {
*/
_storeResult(path, err, result) {
if (this._data.has(path)) return;

if (err) {
// Clone error object to be stored in cache to allow for the original
// error, and its internal representation to be picked up by GC. Thus
// reducing the memory footprint of caching such results in memory.
// Also, omitting expensive calculation of the stacktrace as it gets
// ignored most of the time anyway
const lightErrorProps = Object.getOwnPropertyDescriptors(err);
delete lightErrorProps.stack;

err = Object.create(Object.getPrototypeOf(err), lightErrorProps);
}

const level = this._levels[this._currentLevel];
this._data.set(path, { err, result, level });
level.add(path);
Expand Down

0 comments on commit 5fa0bdf

Please sign in to comment.