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

Add more tracing instrumentation #89048

Merged
merged 1 commit into from
Sep 28, 2021
Merged

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Sep 17, 2021

I changed or added all this while working on a branch and pulled it out so we can merge it on its own.

@rust-highfive
Copy link
Collaborator

r? @matthewjasper

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 17, 2021
@rust-log-analyzer

This comment has been minimized.

@jackh726
Copy link
Member

r=me with CI green

r? @jackh726

@oli-obk
Copy link
Contributor Author

oli-obk commented Sep 18, 2021

@bors r=jackh726

@bors
Copy link
Contributor

bors commented Sep 18, 2021

📌 Commit 731d7797b90a37da2a02c9e9d58b17904bd272d6 has been approved by jackh726

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 18, 2021
@bors
Copy link
Contributor

bors commented Sep 18, 2021

☔ The latest upstream changes (presumably #88980) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 18, 2021
@oli-obk oli-obk force-pushed the in_tracing_we_trust branch from 731d779 to a1b308d Compare September 20, 2021 17:28
@oli-obk
Copy link
Contributor Author

oli-obk commented Sep 20, 2021

@bors r=jackh726 rollup

@bors
Copy link
Contributor

bors commented Sep 20, 2021

📌 Commit a1b308d12a93a19d46579cc7603279da93e26c58 has been approved by jackh726

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 20, 2021
@rust-log-analyzer

This comment has been minimized.

@oli-obk
Copy link
Contributor Author

oli-obk commented Sep 20, 2021

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 20, 2021
@oli-obk oli-obk force-pushed the in_tracing_we_trust branch 2 times, most recently from 804c1ac to 1443de7 Compare September 21, 2021 14:27
@oli-obk
Copy link
Contributor Author

oli-obk commented Sep 23, 2021

@bors r=jackh726 rollup

@bors
Copy link
Contributor

bors commented Sep 23, 2021

📌 Commit 1443de7 has been approved by jackh726

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 23, 2021
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Sep 23, 2021
…h726

Add more tracing instrumentation

I changed or added all this while working on a branch and pulled it out so we can merge it on its own.
@bors
Copy link
Contributor

bors commented Sep 23, 2021

☔ The latest upstream changes (presumably #89024) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 23, 2021
@jackh726
Copy link
Member

@bors p=1

This is prone to bitrot.

@jackh726
Copy link
Member

@bors rollup=never

Same reason

@bors
Copy link
Contributor

bors commented Sep 27, 2021

🔒 Merge conflict

This pull request and the master branch diverged in a way that cannot be automatically merged. Please rebase on top of the latest master branch, and let the reviewer approve again.

How do I rebase?

Assuming self is your fork and upstream is this repository, you can resolve the conflict following these steps:

  1. git checkout in_tracing_we_trust (switch to your branch)
  2. git fetch upstream master (retrieve the latest master)
  3. git rebase upstream/master -p (rebase on top of it)
  4. Follow the on-screen instruction to resolve conflicts (check git status if you got lost).
  5. git push self in_tracing_we_trust --force-with-lease (update this PR)

You may also read Git Rebasing to Resolve Conflicts by Drew Blessing for a short tutorial.

Please avoid the "Resolve conflicts" button on GitHub. It uses git merge instead of git rebase which makes the PR commit history more difficult to read.

Sometimes step 4 will complete without asking for resolution. This is usually due to difference between how Cargo.lock conflict is handled during merge and rebase. This is normal, and you should still perform step 5 to update this PR.

Error message
Auto-merging compiler/rustc_typeck/src/check/upvar.rs
Auto-merging compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
Auto-merging compiler/rustc_typeck/src/check/expr.rs
Auto-merging compiler/rustc_typeck/src/check/coercion.rs
Auto-merging compiler/rustc_typeck/src/check/check.rs
Auto-merging compiler/rustc_trait_selection/src/traits/select/mod.rs
Auto-merging compiler/rustc_trait_selection/src/traits/select/confirmation.rs
Auto-merging compiler/rustc_trait_selection/src/opaque_types.rs
Auto-merging compiler/rustc_resolve/src/lib.rs
Auto-merging compiler/rustc_resolve/src/late/lifetimes.rs
Auto-merging compiler/rustc_middle/src/ty/print/pretty.rs
Auto-merging compiler/rustc_infer/src/infer/nll_relate/mod.rs
Auto-merging compiler/rustc_infer/src/infer/mod.rs
Auto-merging compiler/rustc_infer/src/infer/canonical/query_response.rs
Auto-merging compiler/rustc_data_structures/src/graph/scc/mod.rs
Auto-merging compiler/rustc_borrowck/src/type_check/mod.rs
CONFLICT (content): Merge conflict in compiler/rustc_borrowck/src/type_check/mod.rs
Auto-merging compiler/rustc_borrowck/src/type_check/canonical.rs
Auto-merging compiler/rustc_borrowck/src/lib.rs
Automatic merge failed; fix conflicts and then commit the result.

@oli-obk oli-obk force-pushed the in_tracing_we_trust branch from 1443de7 to 9b5aa06 Compare September 28, 2021 12:28
@oli-obk
Copy link
Contributor Author

oli-obk commented Sep 28, 2021

@bors r=jackh726

@bors
Copy link
Contributor

bors commented Sep 28, 2021

📌 Commit 9b5aa06 has been approved by jackh726

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 28, 2021
@bors
Copy link
Contributor

bors commented Sep 28, 2021

⌛ Testing commit 9b5aa06 with merge 8f8092c...

@bors
Copy link
Contributor

bors commented Sep 28, 2021

☀️ Test successful - checks-actions
Approved by: jackh726
Pushing 8f8092c to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 28, 2021
@bors bors merged commit 8f8092c into rust-lang:master Sep 28, 2021
@rustbot rustbot added this to the 1.57.0 milestone Sep 28, 2021
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8f8092c): comparison url.

Summary: This change led to very large relevant mixed results 🤷 in compiler performance.

  • Large improvement in instruction counts (up to -1.6% on full builds of keccak)
  • Very large regression in instruction counts (up to 12.0% on full builds of ctfe-stress-4)

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression

@rustbot rustbot added the perf-regression Performance regression. label Sep 28, 2021
@oli-obk
Copy link
Contributor Author

oli-obk commented Sep 28, 2021

Uhhhh... why does instrumentation affect release builds?? I'll go through all attributes in this PR and check them again

@oli-obk oli-obk deleted the in_tracing_we_trust branch September 29, 2021 12:24
@oli-obk
Copy link
Contributor Author

oli-obk commented Sep 29, 2021

Ok found it. The instrument attribute will still generate a wrapper function, even if the level is statically rejected. LLVM will then not optimize this as well. I will open a PR to tracing.

@oli-obk
Copy link
Contributor Author

oli-obk commented Sep 30, 2021

#89363 shows a path to fix this regression.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Sep 30, 2021
hawkw pushed a commit to tokio-rs/tracing that referenced this pull request Sep 30, 2021
…o anything (#1600)

## Motivation

Adding `#[instrument(level = "debug")]` attributes to functions in rustc
caused a performance regression (in release, where `debug!` is fully
optimized out) across all crates:
rust-lang/rust#89048 (comment)

While trying to debug this, I noticed that spans don't have the same
advantage that events have wrt to how LLVM sees them. Spans (or more
precisely, the enter-guard), will get dropped at the end of the scope,
which throws a spanner into the LLVM optimization pipeline. I am not
entirely sure where the problem is, but I am moderately certain that the
issue is that even entering a dummy span is too much code for LLVM to
reliably (or at all) optimize out.

## Solution

My hope is that in trusting the Rust compiler to generate cool code when using
drop flags, we can essentially generate a drop flag that depends on something we
know (due to events working as expected) to be optimizable.

So instead of doing

```rust
let _x = span!();
let _y = _x.enter();
// lotsa code
drop(_y)
```

we do

```rust
let _x;
let _y;
let must_drop = false;
if level_enabled!(DEBUG) {
    must_drop = true;
    _x = span!();
    _y = _x.enter();
}
// lotsa code
if must_drop {
    drop(_y)
}
```

I believe this will allow LLVM to properly optimize this again. Testing that
right now, but I wanted to open this PR immediately for review.
hawkw pushed a commit to tokio-rs/tracing that referenced this pull request Oct 1, 2021
…o anything (#1600) (#1605)

## Motivation

Adding `#[instrument(level = "debug")]` attributes to functions in rustc
caused a performance regression (in release, where `debug!` is fully
optimized out) across all crates:
rust-lang/rust#89048 (comment)

While trying to debug this, I noticed that spans don't have the same
advantage that events have wrt to how LLVM sees them. Spans (or more
precisely, the enter-guard), will get dropped at the end of the scope,
which throws a spanner into the LLVM optimization pipeline. I am not
entirely sure where the problem is, but I am moderately certain that the
issue is that even entering a dummy span is too much code for LLVM to
reliably (or at all) optimize out.

## Solution

My hope is that in trusting the Rust compiler to generate cool code when using
drop flags, we can essentially generate a drop flag that depends on something we
know (due to events working as expected) to be optimizable.

So instead of doing

```rust
let _x = span!();
let _y = _x.enter();
// lotsa code
drop(_y)
```

we do

```rust
let _x;
let _y;
let must_drop = false;
if level_enabled!(DEBUG) {
    must_drop = true;
    _x = span!();
    _y = _x.enter();
}
// lotsa code
if must_drop {
    drop(_y)
}
```

I believe this will allow LLVM to properly optimize this again. Testing that
right now, but I wanted to open this PR immediately for review.
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 5, 2021
…imulacrum

Fix performance regression with #[instrument]

linked tracing PR: tokio-rs/tracing#1600

regression introduced by rust-lang#89048
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants