Skip to content

Commit 3791b5d

Browse files
committed
Decouple serde from its derive crate
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 `wasmtime` I'm seeing a reduction from 24.75s to 22.45s when compiling in `release` mode. This is because wasmtime through `gimli` has a dependency on `indexmap` which can only start compiling when `serde` is finished, which you want to happen as early as possible so some of wasmtime's dependencies can start compiling. To measure the full effect, the dependencies can't by themselves activate the `derive` feature. I've upstreamed a patch for `fxprof-processed-profile` which was the only dependency that activated it for `wasmtime` (not yet published to crates.io). `wasmtime-cli` and co. may need patches for their dependencies to see a similar improvement.
1 parent 4cedb3e commit 3791b5d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+212
-120
lines changed

Cargo.lock

+35-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ once_cell = { workspace = true }
4242
listenfd = "1.0.0"
4343
wat = { workspace = true }
4444
serde = { workspace = true }
45+
serde_derive = { workspace = true }
4546
serde_json = { workspace = true }
4647
wasmparser = { workspace = true }
4748
wasm-encoder = { workspace = true }
@@ -235,7 +236,8 @@ async-trait = "0.1.71"
235236
heck = "0.4"
236237
similar = "2.1.0"
237238
toml = "0.5.9"
238-
serde = "1.0.94"
239+
serde = "1.0.188"
240+
serde_derive = "1.0.188"
239241
serde_json = "1.0.80"
240242
glob = "0.3.0"
241243
libfuzzer-sys = "0.4.0"

cranelift/codegen/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ cranelift-control = { workspace = true }
2323
hashbrown = { workspace = true, features = ["raw"] }
2424
target-lexicon = { workspace = true }
2525
log = { workspace = true }
26-
serde = { version = "1.0.94", features = ["derive"], optional = true }
26+
serde = { version = "1.0.188", optional = true }
27+
serde_derive = { version = "1.0.188", optional = true }
2728
bincode = { version = "1.2.1", optional = true }
2829
gimli = { workspace = true, features = ["write"], optional = true }
2930
smallvec = { workspace = true }
@@ -87,6 +88,7 @@ all-arch = [
8788
# For dependent crates that want to serialize some parts of cranelift
8889
enable-serde = [
8990
"serde",
91+
"serde_derive",
9092
"cranelift-entity/enable-serde",
9193
"regalloc2/enable-serde",
9294
"smallvec/serde"

cranelift/codegen/meta/src/gen_inst.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) {
502502
fmt.line(
503503
r#"#[cfg_attr(
504504
feature = "enable-serde",
505-
derive(serde::Serialize, serde::Deserialize)
505+
derive(serde_derive::Serialize, serde_derive::Deserialize)
506506
)]"#,
507507
);
508508

cranelift/codegen/src/binemit/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod stack_map;
88
pub use self::stack_map::StackMap;
99
use core::fmt;
1010
#[cfg(feature = "enable-serde")]
11-
use serde::{Deserialize, Serialize};
11+
use serde_derive::{Deserialize, Serialize};
1212

1313
/// Offset in bytes from the beginning of the function.
1414
///

cranelift/codegen/src/binemit/stack_map.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ const NUM_BITS: usize = core::mem::size_of::<Num>() * 8;
6767
/// live GC references in these slots. We record the `IncomingArg`s in the
6868
/// callee's stack map.
6969
#[derive(Clone, Debug, PartialEq, Eq)]
70-
#[cfg_attr(feature = "enable-serde", derive(serde::Deserialize, serde::Serialize))]
70+
#[cfg_attr(
71+
feature = "enable-serde",
72+
derive(serde_derive::Deserialize, serde_derive::Serialize)
73+
)]
7174
pub struct StackMap {
7275
bitmap: Vec<BitSet<Num>>,
7376
mapped_words: u32,

cranelift/codegen/src/bitset.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use core::ops::{Add, BitOr, Shl, Sub};
1212

1313
/// A small bitset built on a single primitive integer type
1414
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
15-
#[cfg_attr(feature = "enable-serde", derive(serde::Serialize, serde::Deserialize))]
15+
#[cfg_attr(
16+
feature = "enable-serde",
17+
derive(serde_derive::Serialize, serde_derive::Deserialize)
18+
)]
1619
pub struct BitSet<T>(pub T);
1720

1821
impl<T> BitSet<T>

cranelift/codegen/src/incremental_cache.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl std::fmt::Display for CacheKeyHash {
118118
}
119119
}
120120

121-
#[derive(serde::Serialize, serde::Deserialize)]
121+
#[derive(serde_derive::Serialize, serde_derive::Deserialize)]
122122
struct CachedFunc {
123123
// Note: The version marker must be first to ensure deserialization stops in case of a version
124124
// mismatch before attempting to deserialize the actual compiled code.
@@ -139,7 +139,7 @@ struct CacheKey<'a> {
139139
parameters: CompileParameters,
140140
}
141141

142-
#[derive(Clone, PartialEq, Hash, serde::Serialize, serde::Deserialize)]
142+
#[derive(Clone, PartialEq, Hash, serde_derive::Serialize, serde_derive::Deserialize)]
143143
struct CompileParameters {
144144
isa: String,
145145
triple: String,

cranelift/codegen/src/ir/atomic_rmw_op.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use core::fmt::{self, Display, Formatter};
33
use core::str::FromStr;
44
#[cfg(feature = "enable-serde")]
5-
use serde::{Deserialize, Serialize};
5+
use serde_derive::{Deserialize, Serialize};
66

77
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
88
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]

cranelift/codegen/src/ir/condcodes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use core::fmt::{self, Display, Formatter};
88
use core::str::FromStr;
99

1010
#[cfg(feature = "enable-serde")]
11-
use serde::{Deserialize, Serialize};
11+
use serde_derive::{Deserialize, Serialize};
1212

1313
/// Common traits of condition codes.
1414
pub trait CondCode: Copy {

0 commit comments

Comments
 (0)