-
Notifications
You must be signed in to change notification settings - Fork 190
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
Slow compile times / slimming down dependencies #357
Comments
Yeah, lightningcss is some 60,000+ lines of code on top of cssparser so it makes sense that it is slower to compile. Would be awesome to make it faster though. I think we could put the bundler behind a feature flag. That would remove rayon and dash map I think. We can at least see if it improves things. Serde is mostly behind a flag already. I would probably run cargo with the |
Still needs to be compiled in full, so it'll hurt compilation times unless it's removed from the dep tree.
For sure. Running Here is the output of
Confirms that being able to avoid compiling huge dependencies (syn, rayon, etc) would cut down compile time substantially.
Makes sense to me! |
This commit adds a "bundler" feature flag to the lightningcss crate. We put the "dashmap" and "rayon" dependencies behind this new flag. Users that do not need the bundler can now disable the feature to save on compile time. Related: parcel-bundler#357
This commit adds a "bundler" feature flag to the lightningcss crate. We put the "dashmap" and "rayon" dependencies behind this new flag. Users that do not need the bundler can now disable the feature to save on compile time. Related: parcel-bundler#357
This commit makes the "serde" dependency completely optional. Related: parcel-bundler#357
This commit makes the "serde" dependency completely optional. Related: parcel-bundler#357
This disables the default syn features in lightningcss-derive's Cargo.toml. It also removes an unused syn feature. Related: parcel-bundler#357
Submitted a few PRs. I'd like to submit another batch after getting your feedback on the following: I want to submit PR that puts I'd also like to submit a PR that makes This, plus the rest of the PRs would be the final step in getting Well.. not entirely sure about syn.. there might be other things pulling it in.. I need to look at the dep tree more carefully... I'd also like to submit a PR that removes Would these PRs be alright with you? Would you want the Any hesitations here on your end? I'm happy to address whatever is needed to land these. |
Thanks, I'll take a look soon. How much has it helped so far? From the timings, it looked like the lightningcss crate itself was most of the time. |
Yeah looks like lightningcss is about 50% and then deps are the other 50%. I'm focusing on deps first. Once we exhaust all savings there I'd love to help see if there are any potential wins inside of lightningcss's own code that don't hurt performance. For context, my main motivation here is that I want to be able to use lightningcss's Rust API in a few more places in my codebase. Only small savings so far. About 5%. When I combine #358 #360 and #361 into a branch and time a build after cleaning I see about 39 seconds. Before any changes I was seeing about 41 seconds. I'm compiling with 8 cores. The bigger deps are still in the tree. I expect us to see bigger savings when we can make them entirely optional.
Awesome, no rush at all on my end. Thanks so much! |
This commit adds a "bundler" feature flag to the lightningcss crate. We put the "dashmap" and "rayon" dependencies behind this new flag. Users that do not need the bundler can now disable the feature to save on compile time. Related: #357
This disables the default syn features in lightningcss-derive's Cargo.toml. It also removes an unused syn feature. Related: #357
Your other suggestions sound good btw. I think sourcemaps should be on by default (would be pretty commonly used), but visitors could be off by default (more rare). Thanks so much for working on this! |
This commit makes the "serde" dependency completely optional. Related: parcel-bundler#357
This commit adds a "visitor" feature flag to the lightningcss crate. This feature flag controls whether or not the `Visitor` trait gets compiled. The "visitor" flag is disabled by default. Disabling the "visitor" feature disables the `lightningcss-derive` dependency. This commit on its own reduces the lightningcss crate's build time by about 8% (as measured by comparing `cargo build --timings` with and without the "visitor" feature enabled. When combined with some of the other soon to land commits, this commit will make it possible to remove `syn` from the dependency tree when you don't need it, which should lead to substantial compile time savings. Related: parcel-bundler#357
This commit adds a "visitor" feature flag to the lightningcss crate. This feature flag controls whether or not the `Visitor` trait gets compiled. The "visitor" flag is disabled by default. Disabling the "visitor" feature disables the `lightningcss-derive` dependency. This commit on its own reduces the lightningcss crate's build time by about 8% (as measured by comparing `cargo build --timings` with and without the "visitor" feature enabled. When combined with some of the other soon to land commits, this commit will make it possible to remove `syn` from the dependency tree when you don't need it, which should lead to substantial compile time savings. Related: parcel-bundler#357
This commit adds a "visitor" feature flag to the lightningcss crate. This feature flag controls whether or not the `Visitor` trait gets compiled. The "visitor" flag is disabled by default. Disabling the "visitor" feature disables the `lightningcss-derive` dependency. This commit on its own reduces the lightningcss crate's build time by about 8% (as measured by comparing `cargo build --timings` with and without the "visitor" feature enabled. When combined with some of the other soon to land commits, this commit will make it possible to remove `syn` from the dependency tree when you don't need it, which should lead to substantial compile time savings. Related: parcel-bundler#357
This commit adds a "visitor" feature flag to the lightningcss crate. This feature flag controls whether or not the `Visitor` trait gets compiled. The "visitor" flag is disabled by default. Disabling the "visitor" feature disables the `lightningcss-derive` dependency. This commit on its own reduces the lightningcss crate's build time by about 8% (as measured by comparing `cargo build --timings` with and without the "visitor" feature enabled. When combined with some of the other soon to land commits, this commit will make it possible to remove `syn` from the dependency tree when you don't need it, which should lead to substantial compile time savings. Related: parcel-bundler#357
This commit makes the "serde" dependency completely optional. Related: parcel-bundler#357
* Introduce "visitor" feature flag This commit adds a "visitor" feature flag to the lightningcss crate. This feature flag controls whether or not the `Visitor` trait gets compiled. The "visitor" flag is disabled by default. Disabling the "visitor" feature disables the `lightningcss-derive` dependency. This commit on its own reduces the lightningcss crate's build time by about 8% (as measured by comparing `cargo build --timings` with and without the "visitor" feature enabled. When combined with some of the other soon to land commits, this commit will make it possible to remove `syn` from the dependency tree when you don't need it, which should lead to substantial compile time savings. Related: #357 * Specify required features for examples Co-authored-by: Devon Govett <devongovett@gmail.com>
This commit introduces the "sourcemap" feature. Users that do not need sourcemaps can disable this feature and save roughly 15% on compile times. Related to parcel-bundler#357
This commit introduces the "sourcemap" feature. Users that do not need sourcemaps can disable this feature and save roughly 15% on compile times. Related to parcel-bundler#357
This commit introduces the "sourcemap" feature. Users that do not need sourcemaps can disable this feature and save roughly 15% on compile times. Related to parcel-bundler#357
This commit introduces the "sourcemap" feature. Users that do not need sourcemaps can disable this feature and save roughly 15% on compile times. Related to #357
Hey!
Background
I am looking to compile a dynamic library that does some CSS parsing.
The host passes a CSS string to the css dylib.
The css dylib parses the CSS and tracks some information about it internally.
The css dylib returns a modified CSS string to the host.
I am looking to use an existing crate to handle this use case.
I am currently evaluating
lightningcss
andcssparser
.The Problem
I started writing my simple
dylib
usingcssparser
, but quickly found that it was too low level for my needs.After searching on
crates.io
I foundlightningcss
. It was the perfect level of abstraction. I whipped up my css parsing dylib in no time. Great.A day later I noticed that my builds had gotten slower since switching out
cssparser
forlightningcss
.Reproducing
Here's how to see the difference in compile time impact between
cssparser
andlightningcss
.https://github.com/chinedufn/rust-cssparser-and-lightningcss-compile-times
Example Output
Potential Solutions
I looked through
lightningcss
'sCargo.toml
to see if any crates could be made optional.Here are ones that immediately stood out:
Here are ones that could potentially be removed entirely:
Additionally, I wonder if we can turn
default-features = false
forlightningcss-derive
's syn dependencyand only enable exactly what we're using.
Alternative Solutions
css string -> css rules
code as its own crate. Not sure how desirable/feasible that is.Questions
Are you open to trimming down the dependencies?
What other ways could we reduce compile times? Are there places where
lightningcss
uses lots of macros and/or generics that could be simplified?Is there anything that I'm missing? Are the slower compile times unavoidable?
Thank You
lightningcss
was very easy to try out, so thanks!The text was updated successfully, but these errors were encountered: