Skip to content

derived Deserializer methods are slow to compile #727

@jyn514

Description

@jyn514

Here is cargo llvm-lines --lib run on docs.rs: https://gist.github.com/jyn514/3a99fca8e1d3a8048d6bba409b76b381

Note 3 of the top 10 functions are all from serde_json, despite there only being ~20 copies:

  Lines          Copies        Function name
  -----          ------        -------------
  621273 (100%)  15169 (100%)  (TOTAL)
   10599 (1.7%)     17 (0.1%)  <&mut serde_json::de::Deserializer<R> as serde::de::Deserializer>::deserialize_struct
    7930 (1.3%)     26 (0.2%)  <serde_json::de::SeqAccess<R> as serde::de::SeqAccess>::next_element_seed
    4845 (0.8%)     17 (0.1%)  <serde_json::de::MapAccess<R> as serde::de::MapAccess>::next_key_seed

This makes up a full 4% of the lines in the whole 15k line project. Is it at all possible to reduce the size of this functions?

In case it helps, here are some example derives:

https://github.com/rust-lang/docs.rs/blob/master/src/utils/cargo_metadata.rs#L65-L66
https://github.com/rust-lang/docs.rs/blob/master/src/utils/cargo_metadata.rs#L109-110
https://github.com/rust-lang/docs.rs/blob/master/src/utils/cargo_metadata.rs#L130-L131

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions