From cfab887062cf82ddff281cec6a7917318f4a8dff Mon Sep 17 00:00:00 2001 From: Jasper De Moor Date: Sat, 21 Jul 2018 19:43:58 -0700 Subject: [PATCH] Split cache into subdirs for faster fs (#1322) --- packages/core/parcel/src/FSCache.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/core/parcel/src/FSCache.js b/packages/core/parcel/src/FSCache.js index 8043b43e66f..fee757bfcec 100644 --- a/packages/core/parcel/src/FSCache.js +++ b/packages/core/parcel/src/FSCache.js @@ -23,13 +23,24 @@ class FSCache { } async ensureDirExists() { + if (this.dirExists) { + return; + } + await fs.mkdirp(this.dir); + + // Create sub-directories for every possible hex value + // This speeds up large caches on many file systems since there are fewer files in a single directory. + for (let i = 0; i < 256; i++) { + await fs.mkdirp(path.join(this.dir, ('00' + i.toString(16)).slice(-2))); + } + this.dirExists = true; } getCacheFile(filename) { let hash = md5(this.optionsHash + filename); - return path.join(this.dir, hash + '.json'); + return path.join(this.dir, hash.slice(0, 2), hash.slice(2) + '.json'); } async getLastModified(filename) {