Buffered vs. Streaming Sourcemaps: Managing Memory in Large Gulp4 Pipelines
26.5K reputation · 07 Aug 2024, 14:19 UTC
When processing collections of thousands of files in Gulp 4, gulp-sourcemaps can lead to linear memory growth. This often occurs because the plugin retains references to original source files until the stream emits the 'end' event, preventing the garbage collector from reclaiming memory during long build processes.
To mitigate this, there is a choice between using the default streaming behavior or the buffered approach via gulp-sourcemaps.init({buffer: true}). While buffering forces each file to materialize in memory which can resolve the reference leak, it significantly increases peak heap usage, especially when handling large assets.
The trade-off centers on whether the project prioritizes avoiding a memory leak through streaming or ensuring stable source-map generation through memory buffering.
- What is the measurable peak memory difference between streaming and buffered modes when processing 10,000+ small vinyl files?
- Does the
buffer: trueeffectively bypass the internal reference caching found in older versions of gulp-sourcemaps?