serde-yaml icon indicating copy to clipboard operation
serde-yaml copied to clipboard

Monomorphization of Deserialize impls is slow

Open ExpHP opened this issue 7 years ago • 2 comments

I show in this thread on URLO how monomorphization of a few serde_yaml Deserialize impls is responsible for at least a third of the --release compile time of all code in my codebase.

I've known this for a long time, but waited on it because I figured incremental compilation would eventually come to the rescue. And it has, on debug builds. But it remains a problem as I find myself diagnosing problems in my software that only arise on inputs too large for debug builds to handle.

I work around this partly by having a dedicated crate just for struct defs with Deserialize impls. This leads to awkward situations like having to define extension traits on my own config types because they are no longer locally defined.


I imagine that, as is often the case, the slow compile time is the compiler trying to produce the fastest parser out there. Everybody loves speed, but there are other parts of my codebase where I value speed highly more than the little bit at the beginning where it reads a config file! Perhaps a compromise can be made.

ExpHP avatar Jun 22 '18 14:06 ExpHP

So far I don't think serde-yaml has had any attention paid to compile times, so hopefully that means there is a lot of room for improvement. I opened https://github.com/dtolnay/serde-yaml/pull/96 as a start.

dtolnay avatar Jun 22 '18 19:06 dtolnay

Before: (note: this is the crate with almost nothing but Deserialize codegen)

00:00:53    Compiling rsp2-tasks-config v0.1.0 (file:///home/lampam/cpp/other/rust/rsp2/src/tasks/config)

After:

00:00:35    Compiling rsp2-tasks-config v0.1.0 (file:///home/lampam/cpp/other/rust/rsp2/src/tasks/config)

Pretty slick! That's a 33% speed up for me too (and a good 15% or so of my total compile time)

ExpHP avatar Jun 22 '18 21:06 ExpHP