Skip to content

Commit e0260db

Browse files
committed
fix(compiler-cli): reduce memory use by source maps
We had high resolution source maps enabled by default which consume a lot of memory and were causing some crashes internally.
1 parent 5d69bf4 commit e0260db

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

‎packages/compiler-cli/preprocessor/src/output_source_map.ts‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import MagicString, {SourceMap, type SourceMapOptions} from 'magic-string';
1010
import type {ExpressionPrinter, PrintedSnippet} from './output_ast_printer.js';
1111

1212
/** Options for `OutputSourceMapBuilder.generateMap`, a subset of MagicString's. */
13-
export type OutputSourceMapOptions = Pick<
14-
SourceMapOptions,
15-
'file' | 'source' | 'includeContent' | 'hires'
16-
>;
13+
export type OutputSourceMapOptions = Pick<SourceMapOptions, 'file' | 'source' | 'includeContent'>;
1714

1815
/** A piece of compiled text spliced into the output, with the printed snippets it contains. */
1916
interface Insertion {
@@ -58,9 +55,11 @@ export class OutputSourceMapBuilder {
5855
generateMap(options: OutputSourceMapOptions = {}): SourceMap {
5956
const output = this.s.toString();
6057
const sourceName = options.source ?? this.filePath;
61-
// A high-resolution map has a segment for every character of the original text, so a
62-
// position in the output can be resolved exactly rather than relative to a line start.
63-
const decoded = this.s.generateDecodedMap({...options, hires: options.hires ?? true});
58+
const decoded = this.s.generateDecodedMap({
59+
...options,
60+
// Disable high resolution source maps, because they use a lot of memory.
61+
hires: 'boundary',
62+
});
6463
const sources = [...decoded.sources];
6564
const sourcesContent: Array<string | null> | undefined =
6665
decoded.sourcesContent === undefined ? undefined : [...decoded.sourcesContent];

‎packages/compiler-cli/preprocessor/src/processor.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,12 @@ export interface ProcessedFile {
162162
function unprocessedFile(s: MagicString): ProcessedFile {
163163
return {
164164
magicString: s,
165-
generateSourceMap: (options = {}) => s.generateMap({hires: true, ...options}),
165+
generateSourceMap: (options = {}) =>
166+
s.generateMap({
167+
...options,
168+
// Disable high resolution source maps, because they use a lot of memory.
169+
hires: 'boundary',
170+
}),
166171
};
167172
}
168173

0 commit comments

Comments
 (0)