Only use LOCAL_{STDOUT,STDERR} when set_{print/panic} is used. #77264
Merged
bors merged 3 commits intorust-lang:masterfrom Oct 3, 2020
Merged
Only use LOCAL_{STDOUT,STDERR} when set_{print/panic} is used. #77264bors merged 3 commits intorust-lang:masterfrom
bors merged 3 commits intorust-lang:masterfrom
Conversation
Contributor
|
(rust_highfive has picked a reviewer for you, use r? to override) |
The thread local LOCAL_STDOUT and LOCAL_STDERR are only used by the test crate to capture output from tests when running them in the same process in differen threads. However, every program will check these variables on every print, even outside of testing. This involves allocating a thread local key, and registering a thread local destructor. This can be somewhat expensive. This change keeps a global flag (LOCAL_STREAMS) which will be set to true when either of these local streams is used. (So, effectively only in test and benchmark runs.) When this flag is off, these thread locals are not even looked at and therefore will not be initialized on the first output on every thread, which also means no thread local destructors will be registered.
d132cf6 to
de597fc
Compare
Member
Author
|
cc @fasterthanlime whose blogpost inspired this change |
Member
Author
|
@rustbot modify labels: +T-libs +A-io |
Member
|
@bors r+ |
Collaborator
|
📌 Commit de597fc has been approved by |
Member
|
You could use a thread-local |
Member
Author
|
@eddyb Considering that these LOCAL_* streams are only used in tests/benchmarks, I think a global flag makes sense here. In all regular programs, this flag will be permanently off. In tests/benchmarks, the local streams are used on pretty much every thread. And a global flag is efficient on all platforms, not only those supporting |
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Oct 2, 2020
…as-schievink Rollup of 8 pull requests Successful merges: - rust-lang#75377 (Fix Debug implementations of some of the HashMap and BTreeMap iterator types) - rust-lang#76107 (Write manifest for MAJOR.MINOR channel to enable rustup convenience) - rust-lang#76745 (Move Wrapping<T> ui tests into library) - rust-lang#77182 (Add missing examples for Fd traits) - rust-lang#77251 (Bypass const_item_mutation if const's type has Drop impl) - rust-lang#77264 (Only use LOCAL_{STDOUT,STDERR} when set_{print/panic} is used. ) - rust-lang#77421 (Revert "resolve: Avoid "self-confirming" import resolutions in one more case") - rust-lang#77452 (Permit ty::Bool in const generics for v0 mangling) Failed merges: r? `@ghost`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The thread local
LOCAL_STDOUTandLOCAL_STDERRare only used by thetestcrate to capture output from tests when running them in the same process in differen threads. However, every program will check these variables on every print, even outside of testing.This involves allocating a thread local key, and registering a thread local destructor. This can be somewhat expensive.
This change keeps a global flag (
LOCAL_STREAMS) which will be set totruewhen either of these local streams is used. (So, effectively only in test and benchmark runs.) When this flag is off, these thread locals are not even looked at and therefore will not be initialized on the first output on every thread, which also means no thread local destructors will be registered.Together with #77154, this should make output a little bit more efficient.