Skip to content

[libc++][format] Implements P3107R5 in <print>. #130500

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

Open
wants to merge 3 commits into
base: users/mordante/P3107R5-benchmarks
Choose a base branch
from

Conversation

mordante
Copy link
Member

@mordante mordante commented Mar 9, 2025

The followup paper P3235R3 which is voted in as a DR changes the names foo_locking to foo_buffered. These changes have been applied in this patch.

Before

Benchmark Time CPU Iterations

printf 71.3 ns 71.3 ns 9525175
print_string 226 ns 226 ns 3105850
print_stack 232 ns 232 ns 3026498
print_direct 530 ns 530 ns 1318447

After

Benchmark Time CPU Iterations

printf 70.6 ns 70.6 ns 9789585
print_string 222 ns 222 ns 3147678
print_stack 227 ns 227 ns 3084767
print_direct 474 ns 474 ns 1472786

Note: The performance of libc++'s std::print is still extemely slow compared to printf. Based on P3107R5 std::print should outperform printf. The main culprit is the call to isatty, which is resolved after implementing
LWG4044 Confusing requirements for std::print on POSIX platforms

Implements

  • P3107R5 - Permit an efficient implementation of std::print

Implements parts of

  • P3235R3 std::print more types faster with less memory

Fixes: #105435

Copy link

github-actions bot commented Mar 9, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@mordante mordante force-pushed the users/mordante/P3107R5-implementation branch 7 times, most recently from 3efe358 to 4bd6795 Compare March 11, 2025 19:21
The followup paper P3235R3 which is voted in as a DR changes the names
foo_locking to foo_buffered. These changes have been applied in this
patch.

Before
-------------------------------------------------------
Benchmark             Time             CPU   Iterations
-------------------------------------------------------
printf             71.3 ns         71.3 ns      9525175
print_string        226 ns          226 ns      3105850
print_stack         232 ns          232 ns      3026498
print_direct        530 ns          530 ns      1318447

After
-------------------------------------------------------
Benchmark             Time             CPU   Iterations
-------------------------------------------------------
printf             70.6 ns         70.6 ns      9789585
print_string        222 ns          222 ns      3147678
print_stack         227 ns          227 ns      3084767
print_direct        474 ns          474 ns      1472786

Note: The performance of libc++'s std::print is still extemely slow
compared to printf. Based on P3107R5 std::print should outperform
printf. The main culprit is the call to isatty, which is resolved
after implementing
LWG4044  Confusing requirements for std::print on POSIX platforms

Implements
- P3107R5 - Permit an efficient implementation of ``std::print``

Implements parts of
- P3235R3 std::print more types faster with less memory

Fixes: #105435
@mordante mordante force-pushed the users/mordante/P3107R5-implementation branch 2 times, most recently from 071b6c1 to 7ab2024 Compare March 13, 2025 19:01
@mordante mordante force-pushed the users/mordante/P3107R5-implementation branch from 7ab2024 to 4fcce8d Compare March 14, 2025 16:12
mordante added a commit to mordante/llvm-project that referenced this pull request Mar 14, 2025
This was discovered when using this name in llvm#130500.
mordante added a commit that referenced this pull request Mar 16, 2025
This was discovered when using this name in #130500.
@mordante mordante force-pushed the users/mordante/P3107R5-implementation branch from fb15f9b to 4b0bd31 Compare March 16, 2025 19:32
@mordante mordante force-pushed the users/mordante/P3107R5-implementation branch from 4b0bd31 to b190535 Compare March 17, 2025 17:04
@mordante mordante marked this pull request as ready for review April 1, 2025 15:22
@mordante mordante requested a review from a team as a code owner April 1, 2025 15:22
template <class = void> // TODO PRINT template or availability markup fires too eagerly (http://llvm.org/PR61563).
_LIBCPP_HIDE_FROM_ABI inline void
__vprint_nonunicode(FILE* __stream, string_view __fmt, format_args __args, bool __write_nl) {
_LIBCPP_HIDE_FROM_ABI inline void __flockfile(FILE* __stream) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should take the opportunity to introduce a proper "platform layer" for these functions. Something similar to what we do in libcxx/include/__thread/support.h or libcxx/include/__locale_dir/locale_base_api.h, or libcxx/include/__atomic/support.h. I think we might be able to grow this into something more generally useful for other parts of the library.

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.

2 participants