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

Reduce the amount of llvm IR generated #1903

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

Conversation

Marwes
Copy link
Contributor

@Marwes Marwes commented Jan 29, 2021

Rusoto generates a lot of code for each of its services which is noticable in its long compile time. These few commits follows the same ideas as in #1773 . Commonly generated code are extracted into helper functions that can be reused and wherever possible this are written in a manner to not have any type parameters so the code is only instantiated once.

On the s3 crate this reduces the amount of generated LLVM IR by ~21% (400099 / 503440 = 0.79473025584)

Before

  Lines          Copies        Function name
  -----          ------        -------------
  503440 (100%)  10403 (100%)  (TOTAL)
   53787 (10.7%)  1359 (13.1%) core::ptr::drop_in_place
   46645 (9.3%)     95 (0.9%)  rusoto_s3::generated::S3Client::sign_and_dispatch::{{closure}}
   31374 (6.2%)    124 (1.2%)  rusoto_core::proto::xml::util::deserialize_elements
   25451 (5.1%)     42 (0.4%)  rusoto_core::proto::xml::util::parse_response::{{closure}}
   11934 (2.4%)    234 (2.2%)  <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
   10296 (2.0%)    234 (2.2%)  core::pin::Pin<&mut T>::map_unchecked_mut
    6267 (1.2%)     98 (0.9%)  core::result::Result<T,E>::map_err
    6040 (1.2%)    117 (1.1%)  <core::option::Option<T> as core::fmt::Debug>::fmt
    5642 (1.1%)     31 (0.3%)  alloc::raw_vec::RawVec<T,A>::grow_amortized
    4631 (0.9%)    362 (3.5%)  <core::result::Result<T,E> as core::ops::try::Try>::from_error
    3787 (0.8%)    472 (4.5%)  core::pin::Pin<P>::new_unchecked
    3423 (0.7%)    161 (1.5%)  core::ops::function::FnOnce::call_once
    3325 (0.7%)     95 (0.9%)  <rusoto_core::error::RusotoError<E> as core::convert::From<rusoto_core::client::SignAndDispatchError>>::from
    3176 (0.6%)      1 (0.0%)  <rusoto_s3::generated::S3Client as rusoto_s3::generated::S3>::put_object::__put_object::{{closure}}
    3072 (0.6%)     32 (0.3%)  core::iter::traits::exact_size::ExactSizeIterator::len
    2890 (0.6%)    289 (2.8%)  <&T as core::fmt::Debug>::fmt
    2822 (0.6%)     34 (0.3%)  core::fmt::builders::DebugList::entries
    2560 (0.5%)     32 (0.3%)  <alloc::vec::Vec<T,A> as core::iter::traits::collect::IntoIterator>::into_iter
    2322 (0.5%)     27 (0.3%)  core::option::Option<T>::get_or_insert_with
    2320 (0.5%)    232 (2.2%)  core::future::from_generator
    2310 (0.5%)      1 (0.0%)  <rusoto_s3::generated::S3Client as rusoto_s3::generated::S3>::get_object::__get_object::{{closure}}
    2237 (0.4%)      1 (0.0%)  <rusoto_s3::generated::S3Client as rusoto_s3::generated::S3>::copy_object::__copy_object::{{closure}}
    2232 (0.4%)     31 (0.3%)  core::alloc::layout::Layout::array
    2178 (0.4%)     33 (0.3%)  alloc::raw_vec::RawVec<T,A>::current_memory
    2036 (0.4%)      1 (0.0%)  <rusoto_s3::generated::S3Client as rusoto_s3::generated::S3>::head_object::__head_object::{{closure}}
    2033 (0.4%)    406 (3.9%)  <core::result::Result<T,E> as core::ops::try::Try>::into_result
    1995 (0.4%)     95 (0.9%)  rusoto_s3::generated::S3Client::sign_and_dispatch

After

cargo llvm-lines --lib | head -30
  Lines          Copies       Function name
  -----          ------       -------------
  400099 (100%)  8535 (100%)  (TOTAL)
   38832 (9.7%)  1131 (13.3%) core::ptr::drop_in_place
   31374 (7.8%)   124 (1.5%)  rusoto_core::proto::xml::util::deserialize_elements
    6511 (1.6%)   102 (1.2%)  core::result::Result<T,E>::map_err
    6040 (1.5%)   117 (1.4%)  <core::option::Option<T> as core::fmt::Debug>::fmt
    5642 (1.4%)    31 (0.4%)  alloc::raw_vec::RawVec<T,A>::grow_amortized
    5049 (1.3%)    99 (1.2%)  <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
    4356 (1.1%)    99 (1.2%)  core::pin::Pin<&mut T>::map_unchecked_mut
    3501 (0.9%)   164 (1.9%)  core::ops::function::FnOnce::call_once
    3420 (0.9%)   269 (3.2%)  <core::result::Result<T,E> as core::ops::try::Try>::from_error
    3072 (0.8%)    32 (0.4%)  core::iter::traits::exact_size::ExactSizeIterator::len
    2907 (0.7%)     1 (0.0%)  <rusoto_s3::generated::S3Client as rusoto_s3::generated::S3>::put_object::__put_object::{{closure}}
    2890 (0.7%)   289 (3.4%)  <&T as core::fmt::Debug>::fmt
    2822 (0.7%)    34 (0.4%)  core::fmt::builders::DebugList::entries
    2560 (0.6%)    32 (0.4%)  <alloc::vec::Vec<T,A> as core::iter::traits::collect::IntoIterator>::into_iter
    2322 (0.6%)    27 (0.3%)  core::option::Option<T>::get_or_insert_with
    2232 (0.6%)    31 (0.4%)  core::alloc::layout::Layout::array
    2221 (0.6%)     1 (0.0%)  <rusoto_s3::generated::S3Client as rusoto_s3::generated::S3>::get_object::__get_object::{{closure}}
    2178 (0.5%)    33 (0.4%)  alloc::raw_vec::RawVec<T,A>::current_memory
    1947 (0.5%)     1 (0.0%)  <rusoto_s3::generated::S3Client as rusoto_s3::generated::S3>::head_object::__head_object::{{closure}}
    1938 (0.5%)     1 (0.0%)  <rusoto_s3::generated::S3Client as rusoto_s3::generated::S3>::copy_object::__copy_object::{{closure}}
    1855 (0.5%)    35 (0.4%)  core::slice::iter::Iter<T>::new
    1766 (0.4%)     1 (0.0%)  <rusoto_s3::generated::S3Client as rusoto_s3::generated::S3>::create_multipart_upload::__create_multipart_upload::{{closure}}
    1733 (0.4%)    31 (0.4%)  alloc::vec::Vec<T,A>::push
    1715 (0.4%)    35 (0.4%)  core::slice::iter::Iter<T>::post_inc_start
    1680 (0.4%)    42 (0.5%)  rusoto_core::proto::xml::util::<impl core::convert::From<rusoto_core::proto::xml::util::XmlResponseError> for rusoto_core::error::RusotoError<E>>::from
    1627 (0.4%)   202 (2.4%)  core::pin::Pin<P>::new_unchecked
    1610 (0.4%)    35 (0.4%)  <core::slice::iter::Iter<T> as core::iter::traits::iterator::Iterator>::next

Copy link

@dacut dacut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a maintainer, but in case a maintainer needs some time saving here: I've reviewed these, and they're all what they say they do -- getting rid of extra .to_string() calls littered throughout the code.

(This applies to commits aeffede and 92f680c).

Copy link

@dacut dacut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a maintainer -- just hoping this helps the maintainers.
Just had one question about the change from the HttpDispatch error variant to Unknown in a couple places.

let mut response = self.client.sign_and_dispatch(request).await?;
if !response.status.is_success() {{
let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the rationale for changing the returned variant from HttpDispatch to Unknown here? I'm imagine this might break a few clients, and I would think HttpDispatch is more appropriate -- but feel free to set me straight here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should still be HttpDispatch though? It just gets wrapped by the From impl instead?

let mut response = self.client.sign_and_dispatch(request).await?;
if !response.status.is_success() {{
let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as for codegen/query.rs -- not sure about the rationale for changing from the HttpDispatch variant to Unknown.

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

Successfully merging this pull request may close these issues.

None yet

2 participants