rust-lang / rust-lang/cargo

Support a crate flag to recommend optimization

Open
#8,501 2 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-profiles C-feature-request S-needs-design
Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

Description

As a further enhancement to https://github.com/rust-lang/cargo/pull/8500 , we'd like to have an option in Cargo.toml for a library crate to specify that it should almost always be optimized unless specifically requested otherwise.

This would be for crates like phf or lalrpop or munkres, where the optimization level makes a massive performance difference.

We could pay attention to this option whenever we're building with a "default" opt-level of 0, such as for build-dependencies with https://github.com/rust-lang/cargo/pull/8500 , or for dev/test builds. If a crate explicitly says that the dependency should use opt-level 0, we would do that, but if we're only using opt-level 0 because of a built-in default, then a dependency's Cargo.toml specifying to optimize it would be respected.

I'd suggest an option like default-optimized = true.

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 by reading the behavior proposed in PR #8500 and the Cargo.toml configuration described here, then trace how default opt-level 0 is applied to build, dev, and test dependencies. Done means a documented crate-level optimization recommendation that respects explicit opt-level 0 requests while overriding only built-in defaults, with coverage for the stated cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.