Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Reduce the amount of llvm IR generated #1848

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

Marwes
Copy link
Contributor

@Marwes Marwes commented Jul 3, 2020

There are several orthogonal commits here which could be removed if they aren't wanted.

In total this reduces the IR generated by ~5.5% (105103 / 111368 = 0.94374506142) in the twitter example of https://github.com/serde-rs/json-benchmark

Before

cargo llvm-lines  --bin json-benchmark --no-default-features --features lib-serde,file-twitter,performance | rg '(serde|TOTAL)' | head -31
    Updating crates.io index
   Compiling json-benchmark v0.0.1 (/home/markus/Code/json-benchmark)
    Finished dev [unoptimized + debuginfo] target(s) in 3.19s
  111368 (100%)  1640 (100%)  (TOTAL)
   13186 (11.8%)   43 (2.6%)  <serde_json::de::SeqAccess<R> as serde::de::SeqAccess>::next_element_seed
    9397 (8.4%)    15 (0.9%)  <&mut serde_json::de::Deserializer<R> as serde::de::Deserializer>::deserialize_struct
    5430 (4.9%)     1 (0.1%)  <json_benchmark::copy::twitter::_::<impl serde::de::Deserialize for json_benchmark::copy::twitter::User>::deserialize::__Visitor as serde::de::Visitor>::visit_map
    4267 (3.8%)    15 (0.9%)  <serde_json::de::MapAccess<R> as serde::de::MapAccess>::next_key_seed
    3939 (3.5%)    39 (2.4%)  <serde_json::ser::Compound<W,F> as serde::ser::SerializeMap>::serialize_value
    3262 (2.9%)     1 (0.1%)  <json_benchmark::copy::twitter::_::<impl serde::de::Deserialize for json_benchmark::copy::twitter::Status>::deserialize::__Visitor as serde::de::Visitor>::visit_map
    3151 (2.8%)     1 (0.1%)  <json_benchmark::copy::twitter::_::<impl serde::de::Deserialize for json_benchmark::copy::twitter::User>::deserialize::__Visitor as serde::de::Visitor>::visit_seq
    2722 (2.4%)     7 (0.4%)  <&mut serde_json::de::Deserializer<R> as serde::de::Deserializer>::deserialize_seq
    2353 (2.1%)    38 (2.3%)  <serde_json::de::MapAccess<R> as serde::de::MapAccess>::next_value_seed
    1947 (1.7%)     1 (0.1%)  <json_benchmark::copy::twitter::_::<impl serde::de::Deserialize for json_benchmark::copy::twitter::Status>::deserialize::__Visitor as serde::de::Visitor>::visit_seq
    1888 (1.7%)     1 (0.1%)  <json_benchmark::copy::twitter::_::<impl serde::de::Deserialize for json_benchmark::copy::twitter::Media>::deserialize::__Visitor as serde::de::Visitor>::visit_map
    1864 (1.7%)    15 (0.9%)  <serde_json::de::MapKey<R> as serde::de::Deserializer>::deserialize_any
    1789 (1.6%)     7 (0.4%)  <&mut serde_json::de::Deserializer<R> as serde::de::Deserializer>::deserialize_str
    1626 (1.5%)     6 (0.4%)  serde_json::de::Deserializer<R>::deserialize_number
    1557 (1.4%)    39 (2.4%)  serde::ser::SerializeMap::serialize_entry
    1422 (1.3%)     6 (0.4%)  serde::ser::Serializer::collect_seq
    1321 (1.2%)    10 (0.6%)  <&mut serde_json::de::Deserializer<R> as serde::de::Deserializer>::deserialize_option
    1291 (1.2%)     1 (0.1%)  <json_benchmark::copy::twitter::_::<impl serde::de::Deserialize for json_benchmark::copy::twitter::SearchMetadata>::deserialize::__Visitor as serde::de::Visitor>::visit_map
    1013 (0.9%)     1 (0.1%)  <json_benchmark::copy::twitter::_::<impl serde::de::Deserialize for json_benchmark::copy::twitter::Media>::deserialize::__Visitor as serde::de::Visitor>::visit_seq
     988 (0.9%)    28 (1.7%)  <serde::private::de::missing_field::MissingFieldDeserializer<E> as serde::de::Deserializer>::deserialize_any
     946 (0.8%)    38 (2.3%)  serde::private::de::missing_field
     867 (0.8%)     1 (0.1%)  <json_benchmark::copy::twitter::_::<impl serde::de::Deserialize for json_benchmark::copy::twitter::StatusEntities>::deserialize::__Visitor as serde::de::Visitor>::visit_map
     854 (0.8%)     1 (0.1%)  json_benchmark::copy::twitter::_::<impl serde::ser::Serialize for json_benchmark::copy::twitter::User>::serialize
     817 (0.7%)     1 (0.1%)  <json_benchmark::copy::twitter::_::<impl serde::de::Deserialize for json_benchmark::copy::twitter::UserMention>::deserialize::__Visitor as serde::de::Visitor>::visit_map
     777 (0.7%)     7 (0.4%)  <serde_json::ser::Compound<W,F> as serde::ser::SerializeSeq>::serialize_element
     769 (0.7%)     1 (0.1%)  <json_benchmark::copy::twitter::_::<impl serde::de::Deserialize for json_benchmark::copy::twitter::Url>::deserialize::__Visitor as serde::de::Visitor>::visit_map
     729 (0.7%)     1 (0.1%)  <json_benchmark::copy::twitter::_::<impl serde::de::Deserialize for json_benchmark::copy::twitter::SearchMetadata>::deserialize::__Visitor as serde::de::Visitor>::visit_seq
     716 (0.6%)    58 (3.5%)  <core::marker::PhantomData<T> as serde::de::DeserializeSeed>::deserialize
     637 (0.6%)     5 (0.3%)  <serde::de::impls::<impl serde::de::Deserialize for alloc::vec::Vec<T>>::deserialize::VecVisitor<T> as serde::de::Visitor>::visit_seq
     598 (0.5%)     1 (0.1%)  <json_benchmark::copy::twitter::_::<impl serde::de::Deserialize for json_benchmark::copy::twitter::Sizes>::deserialize::__Visitor as serde::de::Visitor>::visit_map

After

cargo llvm-lines  --bin json-benchmark --no-default-features --features lib-serde,file-twitter,performance | rg '(serde|TOTAL)' | head -31
    Updating crates.io index
   Compiling json-benchmark v0.0.1 (/home/markus/Code/json-benchmark)
    Finished dev [unoptimized + debuginfo] target(s) in 3.19s
  105103 (100%)  1681 (100%)  (TOTAL)
   13186 (12.5%)   43 (2.6%)  <serde_json::de::SeqAccess<R> as serde::de::SeqAccess>::next_element_seed
    9397 (8.9%)    15 (0.9%)  <&mut serde_json::de::Deserializer<R> as serde::de::Deserializer>::deserialize_struct
    4267 (4.1%)    15 (0.9%)  <serde_json::de::MapAccess<R> as serde::de::MapAccess>::next_key_seed
    3939 (3.7%)    39 (2.3%)  <serde_json::ser::Compound<W,F> as serde::ser::SerializeMap>::serialize_value
    3329 (3.2%)    38 (2.3%)  serde::private::de::next_non_duplicate_value
    2753 (2.6%)     1 (0.1%)  <json_benchmark::copy::twitter::_::<impl serde::de::Deserialize for json_benchmark::copy::twitter::User>::deserialize::__Visitor as serde::de::Visitor>::visit_seq
    2722 (2.6%)     7 (0.4%)  <&mut serde_json::de::Deserializer<R> as serde::de::Deserializer>::deserialize_seq
    2527 (2.4%)     1 (0.1%)  <json_benchmark::copy::twitter::_::<impl serde::de::Deserialize for json_benchmark::copy::twitter::User>::deserialize::__Visitor as serde::de::Visitor>::visit_map
    2353 (2.2%)    38 (2.3%)  <serde_json::de::MapAccess<R> as serde::de::MapAccess>::next_value_seed
    1864 (1.8%)    15 (0.9%)  <serde_json::de::MapKey<R> as serde::de::Deserializer>::deserialize_any
    1789 (1.7%)     7 (0.4%)  <&mut serde_json::de::Deserializer<R> as serde::de::Deserializer>::deserialize_str
    1687 (1.6%)     1 (0.1%)  <json_benchmark::copy::twitter::_::<impl serde::de::Deserialize for json_benchmark::copy::twitter::Status>::deserialize::__Visitor as serde::de::Visitor>::visit_seq
    1626 (1.5%)     6 (0.4%)  serde_json::de::Deserializer<R>::deserialize_number
    1557 (1.5%)    39 (2.3%)  serde::ser::SerializeMap::serialize_entry
    1534 (1.5%)     1 (0.1%)  <json_benchmark::copy::twitter::_::<impl serde::de::Deserialize for json_benchmark::copy::twitter::Status>::deserialize::__Visitor as serde::de::Visitor>::visit_map
    1521 (1.4%)    38 (2.3%)  serde::private::de::extract_field
    1422 (1.4%)     6 (0.4%)  serde::ser::Serializer::collect_seq
    1321 (1.3%)    10 (0.6%)  <&mut serde_json::de::Deserializer<R> as serde::de::Deserializer>::deserialize_option
     988 (0.9%)    28 (1.7%)  <serde::private::de::missing_field::MissingFieldDeserializer<E> as serde::de::Deserializer>::deserialize_any
     946 (0.9%)    38 (2.3%)  serde::private::de::missing_field
     938 (0.9%)     1 (0.1%)  <json_benchmark::copy::twitter::_::<impl serde::de::Deserialize for json_benchmark::copy::twitter::Media>::deserialize::__Visitor as serde::de::Visitor>::visit_map
     923 (0.9%)     1 (0.1%)  <json_benchmark::copy::twitter::_::<impl serde::de::Deserialize for json_benchmark::copy::twitter::Media>::deserialize::__Visitor as serde::de::Visitor>::visit_seq
     854 (0.8%)     1 (0.1%)  json_benchmark::copy::twitter::_::<impl serde::ser::Serialize for json_benchmark::copy::twitter::User>::serialize
     777 (0.7%)     7 (0.4%)  <serde_json::ser::Compound<W,F> as serde::ser::SerializeSeq>::serialize_element
     716 (0.7%)    58 (3.5%)  <core::marker::PhantomData<T> as serde::de::DeserializeSeed>::deserialize
     655 (0.6%)     1 (0.1%)  <json_benchmark::copy::twitter::_::<impl serde::de::Deserialize for json_benchmark::copy::twitter::SearchMetadata>::deserialize::__Visitor as serde::de::Visitor>::visit_map
     645 (0.6%)     1 (0.1%)  <json_benchmark::copy::twitter::_::<impl serde::de::Deserialize for json_benchmark::copy::twitter::SearchMetadata>::deserialize::__Visitor as serde::de::Visitor>::visit_seq
     637 (0.6%)     5 (0.3%)  <serde::de::impls::<impl serde::de::Deserialize for alloc::vec::Vec<T>>::deserialize::VecVisitor<T> as serde::de::Visitor>::visit_seq
     570 (0.5%)    38 (2.3%)  <serde_json::ser::Compound<W,F> as serde::ser::SerializeStruct>::serialize_field
     569 (0.5%)     1 (0.1%)  json_benchmark::copy::twitter::_::<impl serde::ser::Serialize for json_benchmark::copy::twitter::Status>::serialize

@Marwes
Copy link
Contributor Author

Marwes commented Jan 4, 2021

Rebased and add a few more changes which totals up the improvement in my testing to 5.5% (up from 1.7%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant