Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SourceMap performance issue #6411

Closed
JSerFeng opened this issue Nov 12, 2022 · 8 comments · Fixed by #6523
Closed

SourceMap performance issue #6411

JSerFeng opened this issue Nov 12, 2022 · 8 comments · Fixed by #6523
Assignees
Labels
Milestone

Comments

@JSerFeng
Copy link
Contributor

JSerFeng commented Nov 12, 2022

Describe the bug

Input: A large bundle generated by webpack.
minify: 2s without sourcemap, and 20s with sourcemap

When minify and transform very large file, enable source map will have huge impact on performance, very huge impact that sometimes even slower than terser.

Reprod repo here

Config

No response

Playground link

As the file is too large, I think we better download the reprod repo locally

Expected behavior

SourceMap should be slow to generate, but shouldn't be this slow

Actual behavior

2s without sourcemap
20s with sourcemap

Version

1.3.14

Additional context

No response

@JSerFeng JSerFeng added the C-bug label Nov 12, 2022
@kdy1 kdy1 added this to the Planned milestone Nov 12, 2022
@JSerFeng
Copy link
Contributor Author

Additional information.
MacOs Monterey 12.1
CPU: 2.6 GHz Intel Core i7
32 GB mem

@willstott101
Copy link

willstott101 commented Nov 22, 2022

I can repro this with @swc/core but not a locally built swc...

will@will-ubuntu:~/repos/others/swc_sourcemap_perf_issue$ npm run bench

> perf_issue@1.0.0 bench
> esno bench.ts

swc: 1.861s
terser: 23.946s
swc sourcemap: 24.095s
terser sourcemap: 24.888s
will@will-ubuntu:~/repos/others/swc_sourcemap_perf_issue$ npm i ../swc/swc-core-1.3.19.tgz 
...
will@will-ubuntu:~/repos/others/swc_sourcemap_perf_issue$ npm run bench

> perf_issue@1.0.0 bench
> esno bench.ts

swc: 8.311s
terser: 24.047s
swc sourcemap: 8.592s
terser sourcemap: 24.509s

Not sure I can dig more without some additions to CONTRIBUTING.md about building the node package. Evidently I am doing something differently (npm i && npm run build && npm pack 🤷)

I did dig in pure-rust though... and as far as I got was seeing that serializing sourcemaps isn't benched in the minify benchmark.

source_map: Default::default(),
should be BoolOrDataConfig::from_bool(true) I reckon.

Once it is... then the benchmark is massively slowed down (like, x10 slower or worse) by:

debug!("{}-byte char at {:?}", mbc.bytes, mbc.pos);

Commenting that out or even using NODE_LOG=off makes the benchmark reasonable again though. So unless I can repro the @swc/core result with a local build I think I am out of ideas for resolving.

@hardfist
Copy link

@kdy1 It seems that if the sourcefile contains lots chinese characters it will have serious performance problems, most of the time are spent on
PhyjKiqlnx
compared to asci-only file
hpdfsolSAb

when I remove all the chinese character from code, the sourcemap generation cost reduce from 37s to 1s

@kdy1
Copy link
Member

kdy1 commented Nov 28, 2022

@hardfist Can you share a test input?

@hardfist
Copy link

@kdy1
Copy link
Member

kdy1 commented Nov 28, 2022

Let's see if #6523 fixes it.
Performance issue is fixed, but I'm not sure if all souremap tests will pass

kdy1 added a commit that referenced this issue Nov 28, 2022
…ars (#6523)

**Description:**

This PR makes the source map generator cache the previous position instead of searching it from 0 every time.

**Related issue:**

 - Closes #6411.
@JSerFeng
Copy link
Contributor Author

Thanks !

@kdy1 kdy1 modified the milestones: Planned, v1.3.21 Nov 30, 2022
@swc-bot
Copy link
Collaborator

swc-bot commented Dec 30, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Dec 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

5 participants