Skip to content

Same for loop up to 38% slower depending on iterator used #40310

@supercurio

Description

@supercurio

An issue making what would be the same code in C++ running at significantly different speed with Rust stable/beta/nightly depending on:

  • The type of for loop used: for y in buf or for i in 0..buf.len()
  • Whether the input data is contained in a Vec, Array or Array Slice
  • Whether the test algorithm is inside a function used only with Vec or Array, Array Slice inputs but not several of them.

Previously reported as #40044 with imprecision.
Current stable is 1.15.1. The issue exists pre-MIR albeit with slightly different figures.

Real world examples measured on an audio DSP algorithm

arm
  • Raspberry Pi, Rustc 1.15.1: up to 34% slower
armv7
  • Raspberry Pi 3, Rustc 1.15.1: up to 34% slower, Array 4% slower than Vec
  • Nexus 5, Rustc 1.15: up to 38% slower, Array 1% slower than Vec
  • Nexus 5X, Rustc 1.15: up to 18% slower
aarch64
  • Nexus 5X, Rustc 1.15: up to 27% slower
x86-64
  • Core i5-750, Rustc 1.15: up to 18% slower

Test and demo project:
https://github.com/supercurio/rust-issue-vec-array-iterators-perf

Bench results:
https://github.com/supercurio/rust-issue-vec-array-iterators-perf/tree/master/benchs

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions