rust-lang / rust-lang/rust-clippy

[PERF] Instantiations are getting too far

Open
#14,902 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

G-performance-project
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

As the documentation lints got approved, Ty::intern is now the public enemy number one. Today I analyzed all the occurrences of instantiate* functions and all Ty::interns.

Here is a list of all those calls that exceed 65 while running our test suite. Not all of these can be optimized away, but I'm sure that the greatest culprits can be optimized greatly.

There were lots of lints that use the instantiation functions <50 times in the whole test suite, so I'm pretty sure that (almost) any function that uses them > e.g. 5k times can be heavily optimized away.

For Ty::intern directly, only manual_abs_diff.rs::is_sub_expr is directly optimizable (100% of that), but it "only" creates 131 new types.
For instantiations:

  • dereference.rs for_defined_ty 2.25k (calls)
  • impl_hash_with_borrow_str_and_bytes.rs.html - 2.66k ..
  • only_used_in_recursion - 2.66k ..
  • mixed_read_write_in_expression - 20.8k
  • needless_borrows_for_generic_args - 580
  • large_enum_variant - 500
  • ty/mod.rs 2.15k
  • from_over_into - 241
  • needless_match - 322
  • utils/src/lib.rs - 9099
  • functions/results.rs - 9660
  • functions/ref_option.rs - 10488
  • mut_key.rs - 22.8k (@blyxyas)
  • non_copy_const - 1001
  • methods/mod.rs - 9361
  • self_named_constructors - 929
  • useless_asref - 191
  • path_buf_push_overwrite.rs - 168
  • map_clone.rs - 482
  • case_sensitive_file_extension_comparisons - 68
  • unnecessary_to_owned - 469
  • manual_ok_or - 90
  • get_first - 105
  • implicit_clone 107
  • iter_on_single_or_empty_collections - 79
  • unit_return_expecting_ord - 90630 (@blyxyas)
  • mut_reference.rs - 17.7k
  • transmute_undefined_repr - 349
  • needless_pass_by_ref_mut - 80
  • use_self.rs - 964
  • derive.rs - 2.66k
  • rest_pat_in_fully_bound_struct - 89
  • large_const_arrays - 589

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the test suite and inspect the listed instantiate* call sites and Ty::intern usage, starting with the highest-count entries such as utils/src/lib.rs, functions/results.rs, functions/ref_option.rs, and methods/mod.rs. Identify the greatest unnecessary instantiation costs, optimize the applicable sites, and confirm the test suite still passes with reduced calls.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
performance, tooling
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.