rust-lang / rust-lang/rust

Potential Compiler Optimization Issue with &Vec<Vec<T>> vs &[Vec<T>]?

Open
#124,925 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-LLVM C-enhancement
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

rustc version: 1.78

See Godbolt .

In my understanding, the function that accepts &Vec<Vec> should have the same optimization as the function that accepts &[Vec], because &Vec<Vec> can be turned into &[Vec] by simply calling as_slice() or as_mut_slice().
However, I found that &Vec<Vec> may hinder further vectorization in the nested loop, as shown in the above link.

I am wondering whether this is a compiler bug or an intended action?

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

Start with the Rust snippets in the linked Godbolt comparison and reproduce them with rustc 1.78. Compare the generated code for per_pos_add_0 using &Vec<Vec> and per_pos_add_1 using &[Vec] at opt-level=2. Done means establishing whether the difference is an intended limitation or a compiler optimization bug, with a minimized reproducer if applicable.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.