dtolnay / dtolnay/watt

100x slower performance on serde_derive (with recent serde and syn?)

Open
#47 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
1.5k
Forks
31
PR merge metrics
No merged PRs in 30d

Description

I just tried to use watt with serde_derive to improve performance in a project of mine, only to find it got much slower running the derive macros. Just compiling the shim serde_derive crate is of course much faster.

For this snippet:
```rust
use serde_derive::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
pub struct Information {
pub a: Option,
pub b: Option,
pub c: Option,
pub d: Option,
pub e: Option,
pub f: Option,
pub g: Option,
}

fn main() {}
```

`cargo +nightly rustc -- -Z time-passes` gives me:
`time: 2.753; rss: 53MB -> 113MB ( +60MB) macro_expand_crate`

When using the normal serde_derive I get:
`time: 0.027; rss: 53MB -> 75MB ( +21MB) macro_expand_crate`

I am using a patched syn (rebased on master from jakobhellermann's): https://github.com/acshi/syn-watt/tree/watt-feature
And my patched serde is here: https://github.com/acshi/serde/tree/watt
The final shim crate I have is: https://github.com/acshi/serde_derive_wa

I am guessing this might have something to do with using the latest versions of syn and serde? For some reason I found I also had to patch serde_derive to output `r#try!` or I would get compilation errors because `try` is a reserved keyword.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the provided Information snippet with the linked watt-feature syn, watt serde, and serde_derive_wa patches, using `cargo +nightly rustc -- -Z time-passes`. Compare the macro_expand_crate timings with normal serde_derive, then trace the relevant patched dependencies to identify the regression and confirm that the performance difference is resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, wasm
Domain
compilers, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.