Skip to content

Commit f0d8fdd

Browse files
committed
oops: skip source maps for improved performance
1 parent e49e093 commit f0d8fdd

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

internal/bundler/linker.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4203,6 +4203,7 @@ func (c *linkerContext) generateCodeForFileInChunkJS(
42034203
ConstValues: c.graph.ConstValues,
42044204
LegalComments: c.options.LegalComments,
42054205
UnsupportedFeatures: c.options.UnsupportedJSFeatures,
4206+
SourceMap: c.options.SourceMap,
42064207
AddSourceMappings: addSourceMappings,
42074208
InputSourceMap: inputSourceMap,
42084209
LineOffsetTables: lineOffsetTables,
@@ -5324,6 +5325,7 @@ func (c *linkerContext) generateChunkCSS(chunks []chunkInfo, chunkIndex int, chu
53245325
MinifyWhitespace: c.options.MinifyWhitespace,
53255326
ASCIIOnly: c.options.ASCIIOnly,
53265327
LegalComments: c.options.LegalComments,
5328+
SourceMap: c.options.SourceMap,
53275329
AddSourceMappings: addSourceMappings,
53285330
InputSourceMap: inputSourceMap,
53295331
LineOffsetTables: lineOffsetTables,

internal/css_printer/css_printer.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Options struct {
3434

3535
MinifyWhitespace bool
3636
ASCIIOnly bool
37+
SourceMap config.SourceMap
3738
AddSourceMappings bool
3839
LegalComments config.LegalComments
3940
}
@@ -53,11 +54,17 @@ func Print(tree css_ast.AST, options Options) PrintResult {
5354
for _, rule := range tree.Rules {
5455
p.printRule(rule, 0, false)
5556
}
56-
return PrintResult{
57+
result := PrintResult{
5758
CSS: p.css,
5859
ExtractedLegalComments: p.extractedLegalComments,
59-
SourceMapChunk: p.builder.GenerateChunk(p.css),
6060
}
61+
if options.SourceMap != config.SourceMapNone {
62+
// This is expensive. Only do this if it's necessary. For example, skipping
63+
// this if it's not needed sped up end-to-end parsing and printing of a
64+
// large CSS file from 66ms to 52ms (around 25% faster).
65+
result.SourceMapChunk = p.builder.GenerateChunk(p.css)
66+
}
67+
return result
6168
}
6269

6370
func (p *printer) printRule(rule css_ast.Rule, indent int32, omitTrailingSemicolon bool) {

internal/js_printer/js_printer.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3846,6 +3846,7 @@ type Options struct {
38463846
MinifySyntax bool
38473847
ASCIIOnly bool
38483848
LegalComments config.LegalComments
3849+
SourceMap config.SourceMap
38493850
AddSourceMappings bool
38503851
}
38513852

@@ -3905,9 +3906,13 @@ func Print(tree js_ast.AST, symbols js_ast.SymbolMap, r renamer.Renamer, options
39053906
}
39063907
}
39073908

3908-
return PrintResult{
3909+
result := PrintResult{
39093910
JS: p.js,
39103911
ExtractedLegalComments: p.extractedLegalComments,
3911-
SourceMapChunk: p.builder.GenerateChunk(p.js),
39123912
}
3913+
if options.SourceMap != config.SourceMapNone {
3914+
// This is expensive. Only do this if it's necessary.
3915+
result.SourceMapChunk = p.builder.GenerateChunk(p.js)
3916+
}
3917+
return result
39133918
}

0 commit comments

Comments
 (0)