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

cargo clippy is sometimes >20x slower than cargo check (since 1.58.0) #8171

Closed
wtfsck opened this issue Dec 25, 2021 · 5 comments · Fixed by #8182
Closed

cargo clippy is sometimes >20x slower than cargo check (since 1.58.0) #8171

wtfsck opened this issue Dec 25, 2021 · 5 comments · Fixed by #8182
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@wtfsck
Copy link

wtfsck commented Dec 25, 2021

Summary

cargo +beta check takes ~1min to run but cargo +beta clippy takes ~23mins to run.

There's a Rust 1.57.0 issue (maybe this one) that makes compiling some code really slow. However there's no problem with clippy 0.1.57, only with 0.1.58 so I think this is a clippy issue.

cargo check

This is normal.

time command
0m56,532s time cargo +stable check --release --no-default-features --features "std decoder code_asm" --tests
0m52,658s time cargo +beta check --release --no-default-features --features "std decoder code_asm" --tests

cargo clippy

1.57.0: normal, 1.58.0 (beta): way too slow.

time command
1m40,849s time cargo +stable clippy --release --no-default-features --features "std decoder code_asm" --tests
23m26,212s time cargo +beta clippy --release --no-default-features --features "std decoder code_asm" --tests
  • stable: rustc 1.57.0 (f1edd0429 2021-11-29) and clippy 0.1.57 (f1edd04 2021-11-29)
  • beta: rustc 1.58.0-beta.2 (0e07bcb68 2021-12-04) and clippy 0.1.58 (0e07bcb 2021-12-04)

Reproducer

git clone https://github.com/icedland/iced.git
cd iced/src/rust/iced-x86
# execute one of the commands above (see the tables)

Version

rustc 1.57.0 (f1edd0429 2021-11-29)
binary: rustc
commit-hash: f1edd0429582dd29cccacaf50fd134b05593bd9c
commit-date: 2021-11-29
host: x86_64-unknown-linux-gnu
release: 1.57.0
LLVM version: 13.0.0

rustc 1.58.0-beta.2 (0e07bcb68 2021-12-04)
binary: rustc
commit-hash: 0e07bcb68b82b54c0c4ec6fe076e9d75b02109cf
commit-date: 2021-12-04
host: x86_64-unknown-linux-gnu
release: 1.58.0-beta.2
LLVM version: 13.0.0

Additional Labels

No response

@wtfsck wtfsck added the C-bug Category: Clippy is not doing the correct thing label Dec 25, 2021
@llogiq
Copy link
Contributor

llogiq commented Dec 25, 2021

Clippy isn't really optimized, however, it might be beneficial to try and collect a profile to see where the time is spent.

@wtfsck
Copy link
Author

wtfsck commented Dec 27, 2021

Using perf, I get:

cargo +stable clippy

Samples: 375K of event 'cycles:u', Event count (approx.): 342320872755
Overhead  Command        Shared Object                        Symbol
   2,78%  rustc          libc.so.6                            [.] _int_malloc
   2,48%  rustc          librustc_driver-15fe7307aff1f259.so  [.] rustc_middle::hir::map::Map::attrs
   1,89%  rustc          libc.so.6                            [.] _int_free
   1,89%  rustc          libc.so.6                            [.] malloc
   1,81%  rustc          libc.so.6                            [.] unlink_chunk.constprop.0
   1,13%  rustc          librustc_driver-15fe7307aff1f259.so  [.] <rustc_lint::late::LateLintPassObjects as rustc_lint::passes::LateLintPass>::exit_lint_attrs
   1,09%  rustc          librustc_driver-15fe7307aff1f259.so  [.] hashbrown::map::RawEntryBuilderMut<K,V,S,A>::from_hash
   1,04%  rustc          libc.so.6                            [.] malloc_consolidate
   1,01%  rustc          librustc_driver-15fe7307aff1f259.so  [.] <rustc_lint::late::LateLintPassObjects as rustc_lint::passes::LateLintPass>::check_expr
   1,00%  rustc          librustc_driver-15fe7307aff1f259.so  [.] rustc_resolve::Resolver::traits_in_module
   1,00%  rustc          libc.so.6                            [.] cfree@GLIBC_2.2.5
   0,97%  rustc          librustc_driver-15fe7307aff1f259.so  [.] <rustc_lint::late::LateLintPassObjects as rustc_lint::passes::LateLintPass>::check_name
   0,93%  rustc          librustc_driver-15fe7307aff1f259.so  [.] <rustc_lint::late::LateLintPassObjects as rustc_lint::passes::LateLintPass>::enter_lint_attrs
   0,90%  rustc          clippy-driver                        [.] rustc_lint::passes::LateLintPass::exit_lint_attrs
   0,84%  rustc          librustc_driver-15fe7307aff1f259.so  [.] rustc_middle::ty::context::TyCtxt::_intern_substs
   0,76%  rustc          librustc_driver-15fe7307aff1f259.so  [.] rustc_span::symbol::Symbol::intern

cargo +beta check

This is here to show that cargo +beta check is much faster than cargo +beta clippy

Samples: 182K of event 'cycles:u', Event count (approx.): 167246634870
Overhead  Command  Shared Object                        Symbol
   2,43%  rustc    rustc                                [.] free
   2,36%  rustc    librustc_driver-6d26630eb1684640.so  [.] <rustc_resolve::Resolver>::traits_in_scope
   1,99%  rustc    rustc                                [.] malloc
   1,87%  rustc    librustc_driver-6d26630eb1684640.so  [.] <hashbrown::map::RawEntryBuilderMut<rustc_middle::ty::context::Interned<rustc_middle::ty::TyS>, (), core::hash::BuildHasherDefault<rustc_hash::FxHasher>>>::from_hash::<hashbrown::map::equivalent<rustc_middle::ty::sty::TyK
   1,46%  rustc    librustc_driver-6d26630eb1684640.so  [.] <rustc_middle::ty::context::TyCtxt>::const_eval_global_id
   1,42%  rustc    librustc_driver-6d26630eb1684640.so  [.] <hashbrown::map::RawEntryBuilderMut<rustc_middle::ty::context::Interned<rustc_middle::ty::PredicateInner>, (), core::hash::BuildHasherDefault<rustc_hash::FxHasher>>>::from_hash::<hashbrown::map::equivalent<rustc_middle::t
   1,41%  rustc    libc.so.6                            [.] __memmove_sse2_unaligned_erms
   1,17%  rustc    librustc_driver-6d26630eb1684640.so  [.] <smallvec::SmallVec<[rustc_mir_build::thir::pattern::deconstruct_pat::Constructor; 1]> as core::iter::traits::collect::Extend<rustc_mir_build::thir::pattern::deconstruct_pat::Constructor>>::extend::<core::iter::adapters::
   1,02%  rustc    librustc_driver-6d26630eb1684640.so  [.] <rustc_middle::hir::map::Map>::body_owner_def_id
   1,00%  rustc    librustc_driver-6d26630eb1684640.so  [.] <rustc_resolve::Resolver as rustc_ast_lowering::ResolverAstLowering>::get_partial_res
   0,93%  rustc    librustc_driver-6d26630eb1684640.so  [.] <rustc_middle::ty::context::CtxtInterners>::intern_ty
   0,90%  rustc    librustc_driver-6d26630eb1684640.so  [.] <core::iter::adapters::map::Map<core::iter::adapters::map::Map<core::iter::adapters::enumerate::Enumerate<core::slice::iter::Iter<rustc_middle::ty::VariantDef>>, <rustc_index::vec::IndexVec<rustc_target::abi::VariantIdx,
   0,83%  rustc    librustc_driver-6d26630eb1684640.so  [.] <rustc_middle::ty::context::TyCtxt>::intern_substs
   0,80%  rustc    librustc_driver-6d26630eb1684640.so  [.] <rustc_typeck::check::fn_ctxt::FnCtxt>::instantiate_value_path
   0,63%  rustc    librustc_driver-6d26630eb1684640.so  [.] <rustc_middle::hir::map::Map>::attrs
   0,61%  rustc    librustc_driver-6d26630eb1684640.so  [.] <rustc_trait_selection::traits::fulfill::FulfillProcessor>::progress_changed_obligations
   0,58%  rustc    librustc_driver-6d26630eb1684640.so  [.] <rustc_borrowck::type_check::TypeChecker>::typeck_mir

cargo +beta clippy

Samples: 5M of event 'cycles:u', Event count (approx.): 4797014161070
Overhead  Command        Shared Object                        Symbol
  53,17%  rustc          clippy-driver                        [.] <rustc_middle::hir::map::Map>::visit_item_likes_in_module::<clippy_utils::VisitConstTestStruct>
  22,99%  rustc          librustc_driver-6d26630eb1684640.so  [.] <rustc_middle::hir::map::Map>::attrs
  15,43%  rustc          librustc_driver-6d26630eb1684640.so  [.] <rustc_middle::hir::map::Map>::item
   0,41%  rustc          librustc_driver-6d26630eb1684640.so  [.] <rustc_middle::hir::map::Map>::impl_item
   0,23%  rustc          libc.so.6                            [.] _int_malloc
   0,17%  rustc          libc.so.6                            [.] malloc
   0,17%  rustc          librustc_driver-6d26630eb1684640.so  [.] <rustc_hir::hir::OwnerNode>::expect_item
   0,15%  rustc          libc.so.6                            [.] unlink_chunk.constprop.0
   0,14%  rustc          libc.so.6                            [.] _int_free
   0,10%  rustc          libc.so.6                            [.] malloc_consolidate
   0,10%  rustc          librustc_driver-6d26630eb1684640.so  [.] <hashbrown::map::RawEntryBuilderMut<rustc_middle::ty::context::Interned<rustc_middle::ty::TyS>, (), core::hash::BuildHasherDefault<rustc_hash::FxHasher>>>::from_hash::<hashbrown::map::equivalent<rustc_middle::ty::st
   0,09%  rustc          librustc_driver-6d26630eb1684640.so  [.] <rustc_resolve::Resolver>::traits_in_scope
  • stable = 1.57.0
  • beta = 1.58.0

@wtfsck
Copy link
Author

wtfsck commented Dec 27, 2021

clippy_utils::VisitConstTestStruct seems to have been added in this PR: #7811

@llogiq
Copy link
Contributor

llogiq commented Dec 27, 2021

Yeah, that's on me. Unfortunately we still don't have a better way to find test items. I should add some caching to recover most of the lost perf.

@llogiq
Copy link
Contributor

llogiq commented Dec 27, 2021

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants