🚀 A Browserify Cache for Maximum speed.
browserify-persist-fs
stores the computation results for every file
processed in a cache
folder which makes recomputation of previous executions
extremely fast (particularily useful for CI!).
Oh❗️ It also comes with a logging API that can help you figure out why your browserify execution is slow and which files cost most time!
In our production we were able to reduce repeated requests from 40s → 6s 🎉
Temporary disclaimer
In order to user browserify-persist-fs
you need to have a version of browserify
that depends on module-deps
with a
version >= 4.1.0 installed.
By installing a clean version of browserify v14.1.0 or newer,
you will get the required module-deps
version.
Installation & Setup
Specify browserify-persist-fs
as persistentCache
option.
const browserify = // for the time being...const browserifyPersistFs = '.cache' // The folder where things should be stored {} // "hashObject": And object that is used to figure out if the configuration has changed null // Optional log handler (default: null) false // Pass in true to disable the cache (default: false)const bundle =
Identity of builds
When you build something with browserify you can have a lot of ways in to modify
the resulting output: transforms
, debug
, sourcemap
, etc. Since it is
impossible to figure out automatically what properties may exist, you have to
specify how the build is different.
The second property, the hashObject
, should be used to make sure that different
configurations of browserify don't use the same cache directory.
Usually it contains a mixture of version specifications and config flags:
const browserifyPersistFs = '.cache' debug: true transforms: version version version
Make sure that this results in a good idea to ensure developer happiness ☀️ 🙆
A PR to make this process better would be highly welcome.
Garbage Collection
browserify-persist-fs
does not automatically delete old cache files. You will
run out of disk space if the old files are not regularly deleted.
browserify-persist-fs
offers an API that allows you to delete old files:
const browserifyPersistFs = '.cache' /*...*/ browserifyPersistFs
You have to specify at least maxAge
, maxCount
or maxSize
. Any combination
is possible as well.
Logging
const browserifyPersistFs = '.cache' {} log { entryfile // File that has been loaded entryerr // In case an error occurred entrycacheFile // The cache file location that has been used entrydurationstotal // Total time it took to process this entry entrydurationsread // Time it took to read the source file entrydurationscache // Time it took to read the cached content entrydurationsgenerate // Time it took to generate the resulting file entrysizesinput // Size of the input file entrysizesoutput // Size of the output file}
Statistics
Using the above-mentioned Logging capabilities it is possible to generate statistics about the project that you are rendering. These statistics can give clarity about why builds are slow and if everything worked right.
browserify-persist-fs
comes with a small statistics module that can generate
a useful view:
const stats = const browserifyPersistFs = '.cache' {} statsupdate // ...// After processing and gc: browserifyPersistFs
which should show something like:
Avg. duration pre file for reading: 109.9ms
Avg. duration per file for generating: 1ms
Files built: 0
Files with error: 0
Files cached: 1155
Garbage collected files: 0
Slowest files:
- /Users/martinheidegger/project/client/js/app/components/draw/DrawObjectText.js (total: 257ms, reading: 105.96ms, generating: 1ms)
- /Users/martinheidegger/project/client/js/app/components/draw/DrawObjectCanvas.js (total: 255.98ms, reading: 106.21ms, generating: 1ms)
- /Users/martinheidegger/project/node_modules/rgb2hex/index.js (total: 255.9ms, reading: 126.53ms, generating: 1ms)
- /Users/martinheidegger/project/client/js/app/components/draw/DrawObjectPen.js (total: 255.73ms, reading: 106.07ms, generating: 1ms)
- /Users/martinheidegger/project/client/js/app/components/draw/StampTool.js (total: 254.7ms, reading: 105.96ms, generating: 1ms)
- /Users/martinheidegger/project/client/js/app/components/draw/ToolButtons.js (total: 254.68ms, reading: 106.23ms, generating: 1ms)
- /Users/martinheidegger/project/node_modules/react-bootstrap/lib/utils/index.js (total: 252.14ms, reading: 129.16ms, generating: 1ms)
- /Users/martinheidegger/project/node_modules/jsondiffpatch/src/main.js (total: 247.01ms, reading: 130.37ms, generating: 1ms)
- /Users/martinheidegger/project/node_modules/react/lib/ReactPropTypeLocationNames.js (total: 244.29ms, reading: 101.02ms, generating: 1ms)
- /Users/martinheidegger/project/node_modules/react/lib/checkReactTypeSpec.js (total: 244.31ms, reading: 99.56ms, generating: 1ms)
- /Users/martinheidegger/project/node_modules/react/lib/canDefineProperty.js (total: 244.21ms, reading: 101.09ms, generating: 1ms)
- /Users/martinheidegger/project/node_modules/react/lib/traverseAllChildren.js (total: 244.21ms, reading: 100.87ms, generating: 1ms)
- /Users/martinheidegger/project/node_modules/react/lib/ReactPropTypesSecret.js (total: 243.18ms, reading: 99.58ms, generating: 1ms)
- /Users/martinheidegger/project/node_modules/react/lib/reactProdInvariant.js (total: 242.94ms, reading: 101.01ms, generating: 1ms)
- /Users/martinheidegger/project/node_modules/react/lib/PooledClass.js (total: 243.1ms, reading: 100.84ms, generating: 1ms)
- /Users/martinheidegger/project/node_modules/react/lib/ReactComponentTreeHook.js (total: 243.02ms, reading: 99.56ms, generating: 1ms)
- /Users/martinheidegger/project/node_modules/react/lib/ReactNoopUpdateQueue.js (total: 242.93ms, reading: 99.58ms, generating: 1ms)
- /Users/martinheidegger/project/node_modules/react/lib/getIteratorFn.js (total: 241.89ms, reading: 99.83ms, generating: 1ms)
- /Users/martinheidegger/project/node_modules/react/lib/ReactElementSymbol.js (total: 241.83ms, reading: 98.3ms, generating: 1ms)
- /Users/martinheidegger/project/node_modules/react/lib/ReactCurrentOwner.js (total: 241.67ms, reading: 98.31ms, generating: 1ms)
License
MIT
Mentions
I was able to work on this thanks to Nota that produces Scrapbox and Gyazo since we needed this to make our build run on speed!🏃