babel / babel/babel-loader

Consider not parsing/stringifying cached transform

Open
#572 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
4.8k
Forks
456
Avg merge
9h 19m
Merged PRs (30d)
2

Description

**Babel Loader Version**:
current (8.0.0-beta.0) but I believe it stays since beginning (or at least 6.x)

**Current behavior:**
When `cacheDirectory` option is set, `babel-loader` before/after zipping (https://github.com/babel/babel-loader/issues/571) performs `JSON.stringify`/`JSON.parse` to store the `{ code, map, metadata }` from `babel.transform()` call

**Expected/desired behavior:**
We need to store just 2 types of data: `code` and `map`. BTW, what are valid cases for using Babel's metadata field? We could still provide it, but in my brief testing the object was always empty, so I got a bit confused here.

When using inline source maps with e.g. `devtool: 'eval'` (which happen to be used while development, which in my experience is the environment where `cacheDirectory` is set usually), we end up with map bundled with transform, so we only need to store `code` for most cases. The other case is when source map is another file and we'll cover that too.

So for both cases we're able to get rid of `JSON.stringify`/`JSON.parse` (and we want to, as these are pretty slow).
* inline source maps: we end up with just one cache file per source being written to disk
* non-inline source maps: we end up with 2 cache files per source being written to disk (I'd like not to mix these two into one file, but that's also possible)

Even when using non-inline source maps, the benefit of not-calling `JSON.stringify`/`JSON.parse` should outrun the drawback of having 2x fs calls.

Would you be interested in accepting a PR changing current behavior?

Combined with https://github.com/babel/babel-loader/issues/571 this should result in some nice perf wins.

Contributor guide

Open the contributing guide

Research direction

The issue identifies babel-loader's cacheDirectory handling and Babel's transform result as the entry points; no specific files or tests are named. Start by tracing cache reads and writes for inline and separate source maps, then verify that code and maps remain usable without JSON.parse/stringify while resolving how metadata should be handled.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, webpack
Domain
build-system, performance, tooling
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.