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

improve sourcemap performance #1881

Conversation

romainmenke
Copy link
Contributor

@romainmenke romainmenke commented Sep 16, 2023

related change to PostCSS benchmarks : postcss/benchmark#32

lib/map-generator.js Show resolved Hide resolved
Comment on lines 21 to 23
this.memoizedFileURLs = new Map();
this.memoizedPaths = new Map();
this.memoizedURLs = new Map();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specific operations were done very frequently and were slow.
As far as I can tell these can be memoized.
This dramatically improves performance of sourcemap generation.

I don't have a strong opinion on naming or best practices here.
Please advice if there is a more idiomatic way to memoize these values within PostCSS.

@ai
Copy link
Member

ai commented Sep 16, 2023

Can you show the benchmark results (before/after) on you machine?

@romainmenke
Copy link
Contributor Author

On my machine (M2 air) :

[22:24:27] Running suite Sourcemaps [/Users/romainmenke/projects/postcss-benchmark/sourcemaps.js]...
[22:24:33]    PostCSS x 8.41 ops/sec ±2.61% (45 runs sampled)
[22:24:39]    Next PostCSS x 17.42 ops/sec ±3.29% (85 runs sampled)
[22:24:39] Fastest test is Next PostCSS at 2.1x faster than PostCSS

Next PostCSS: 57 ms  (2.1 times faster)
PostCSS:      119 ms

lib/map-generator.js Outdated Show resolved Hide resolved
file = relative(from, file)
return file
let path = relative(from, file)
this.memoizedPaths.set(file, path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

;

romainmenke and others added 2 commits September 16, 2023 22:41
Co-authored-by: Andrey Sitnik <andrey@sitnik.ru>
@ai
Copy link
Member

ai commented Sep 16, 2023

Looks amazing. I will accept it tomorrow. Don’t want to accept and release before going to bed :D.

@ai ai merged commit b2be58a into postcss:main Sep 18, 2023
7 checks passed
@romainmenke romainmenke deleted the improve-sourcemap-performance--philosophical-spiny-dogfish-3eb029c1c8 branch September 18, 2023 21:21
@ai
Copy link
Member

ai commented Sep 18, 2023

Thanks. Released in 8.4.30.

@romainmenke
Copy link
Contributor Author

Awesome! thank you 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants