Decouple serde from its derive crate#65
Merged
Merged
Conversation
By not activating the `derive` feature on `serde`, the compilation speed can be improved by a lot. This is because `serde` can then compile in parallel to `serde_derive`, allowing it to finish compilation possibly even before `serde_derive`, unblocking all the crates waiting for `serde` to start compiling much sooner. As it turns out the main deciding factor for how long the compile time of a project is, is primarly determined by the depth of dependencies rather than the width. In other words, a crate's compile times aren't affected by how many crates it depends on, but rather by the longest chain of dependencies that it needs to wait on. In many cases `serde` is part of that long chain, as it is part of a long chain if the `derive` feature is active: `proc-macro2` compile build script > `proc-macro2` run build script > `proc-macro2` > `quote` > `syn` > `serde_derive` > `serde` > `serde_json` (or any crate that depends on serde) By decoupling it from `serde_derive`, the chain is shortened and compile times get much better. Check this issue for a deeper elaboration: serde-rs/serde#2584 For `samply` I'm seeing a reduction from 5.43s to 3.70s when compiling `fxprof-processed-profile` in `release` mode.
mstange
approved these changes
Aug 27, 2023
mstange
left a comment
Owner
There was a problem hiding this comment.
That's a great result! Thank you!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By not activating the
derivefeature onserde, the compilation speed can be improved by a lot. This is becauseserdecan then compile in parallel toserde_derive, allowing it to finish compilation possibly even beforeserde_derive, unblocking all the crates waiting forserdeto start compiling much sooner.As it turns out the main deciding factor for how long the compile time of a project is, is primarly determined by the depth of dependencies rather than the width. In other words, a crate's compile times aren't affected by how many crates it depends on, but rather by the longest chain of dependencies that it needs to wait on. In many cases
serdeis part of that long chain, as it is part of a long chain if thederivefeature is active:proc-macro2compile build script >proc-macro2run build script >proc-macro2>quote>syn>serde_derive>serde>serde_json(or any crate that depends on serde)By decoupling it from
serde_derive, the chain is shortened and compile times get much better.Check this issue for a deeper elaboration:
serde-rs/serde#2584
For
samplyI'm seeing a reduction from 5.43s to 3.70s when compilingfxprof-processed-profileinreleasemode.The impact is even larger for crates that depend on
fxprof-processed-profilesuch aswasmtime.