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

Optimize away a call to std::io::stdout(). #36

Merged
merged 1 commit into from Jul 4, 2022

Conversation

sunfishcode
Copy link
Contributor

The code added in #33 called std::io::stdout just to call as_raw_fd
on the result. But calling std::io::stdout involves acquiring a lock,
and it doesn't fully optimize away. So instead, call
rustix::io::raw_stdout, which just returns the stdout file descriptor
directly, without doing anything else.

This shaves off 444 bytes of binary size, which is enough to give
terminal-size 0.2 a slightly smaller code-size footprint in release
builds than even terminal-size 0.1.

Previously, this code called `std::io::stdout` just to call
`as_raw_fd` on it. But calling `std::io::stdout` involves acquiring
a lock, and it doesn't fully optimize away. So instead, call
`rustix::io::raw_stdout`, which just returns the stdout file descriptor
directly, without taking a lock.
@eminence eminence merged commit 8e46aea into eminence:master Jul 4, 2022
@eminence
Copy link
Owner

eminence commented Jul 4, 2022

Thanks! Published as v0.2.1

@sunfishcode sunfishcode deleted the main branch July 4, 2022 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants