-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
[performance][windows][stdio] write_valid_utf8_to_console
should almost certainly call MultiByteToWideChar
#107092
Comments
Do we get measurable performance wins that make calling more unsafe C APIs worth it? Especially with the inlining barrier across languages. |
Do we have any good benchmarks for console I/O perf? |
A simple main writing 100MB worth of lines to stdout and measuring the time it takes should do? |
For sure. I was just wondering if we had something already. I mean, we'd probably want to be testing a few different languages as well to make sure we're not just optimizing for ASCII only. |
I don't think we do because most benchmarks suppress console output. |
I did do a benchmark, and interestingly, ASCII text was about twice as fast with See benchmarks at strega-nil/rust-bench-cvt-utf8-utf16. Run on M1 chip:
someone may want to check on an x64 chip, since that might be faster. |
Just to check my understanding: The utf16 conversion only happens when one writes to an actually rendered console. There isn't some stuff like virtual consoles that act more like NUL where speeding up the conversion could help because the data will be discarded by the OS. And output to files is binary anyway. |
There are now (since Windows 10, 1809) pseudo consoles which are consoles without the rendering part. Though the intent would be for the rendering to be implemented by another program, it would also be possible to skip or delay (e.g. by writing a log) rendering. |
In that case a speedup may be useful, but is the optimization potential of the built-in conversion already squeezed dry? |
@the8472 yeah, I think it's unlikely that the added complexity is worth it given what the benchmarks show; I would really appreciate if someone ran the benchmark on x64, since it may be that Windows implements faster algorithms on that platform. |
I don't think anyone has worked on optimizing this so I'm sure there's plenty of optimization potential. The results from I got from an AMD Ryzen 5 3600 machine are:
|
Mmh, thanks @ChrisDenton! I'll also push some benchmarks for testing other cases later, since there are plenty of other cases than just "bulk-converting a bunch of text". Thanks! Nicole |
[stdio][windows] Use MBTWC and WCTMB `MultiByteToWideChar` and `WideCharToMultiByte` are extremely well optimized, and therefore should probably be used when we know we can (specifically in the Windows stdio stuff). Fixes rust-lang#107092
(and similarly,
read_u16s()
should callWideCharToMultiByte
)Windows provides these nice functions which performantly implement utf-8 <-> utf-16 conversions. We should probably call them in the standard library when possible.
The text was updated successfully, but these errors were encountered: