--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAF8qwaDuizS7tVwgHAfDY_6%3DYvkuWa4arr%3DbaohOqYxks1VQQg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAAHOzFBS6hDv%3DjMkcFUaUED_z9tC_1jxcY8vhusFTjjFTMSNWQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAHtyhaQsx9ETxFcfQwwbFeuYORGt7T3c_628pOgGKgDgMwjwSg%40mail.gmail.com.
I've filed https://github.com/llvm/llvm-project/issues/73699 upstream.On Tue, Nov 28, 2023 at 2:07 PM David Benjamin <davi...@chromium.org> wrote:Okay, while supersize isn't showing me the disassembly, most of the files that get larger have a bunch of symbols relating to std::visit internals. Looking at the absl and libc++ visit implementations, I noticed a difference. Abseil compiles std::visit into a switch/case if there are at most 33 cases. Otherwise it falls back to a function pointer table.libc++ seems to always always use the function pointer table.
https://source.chromium.org/chromium/chromium/src/+/main:third_party/libc++/src/include/variant;drc=8e78783dc1f7007bad46d657c9f332614e240fd8;l=274I found this blog post which seems to discuss this a bit. Apparently the C++ standard requires that std::visit be O(1) in the number of choices in the variant. Nevermind that is a compile-time constant. So I guess the conclusion is people believe you have to build a table, rather than chaining conditionals. But jumping through tables is supposedly hard for the compiler to optimize.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAF8qwaBkaFV%2BE6FSjYaGgXmNLUdB1YdCkdiFMEPyFpokPzpP7w%40mail.gmail.com.
On Tue, Nov 28, 2023 at 12:51 PM David Benjamin <davi...@chromium.org> wrote:I've filed https://github.com/llvm/llvm-project/issues/73699 upstream.On Tue, Nov 28, 2023 at 2:07 PM David Benjamin <davi...@chromium.org> wrote:Okay, while supersize isn't showing me the disassembly, most of the files that get larger have a bunch of symbols relating to std::visit internals. Looking at the absl and libc++ visit implementations, I noticed a difference. Abseil compiles std::visit into a switch/case if there are at most 33 cases. Otherwise it falls back to a function pointer table.libc++ seems to always always use the function pointer table.
https://source.chromium.org/chromium/chromium/src/+/main:third_party/libc++/src/include/variant;drc=8e78783dc1f7007bad46d657c9f332614e240fd8;l=274I found this blog post which seems to discuss this a bit. Apparently the C++ standard requires that std::visit be O(1) in the number of choices in the variant. Nevermind that is a compile-time constant. So I guess the conclusion is people believe you have to build a table, rather than chaining conditionals. But jumping through tables is supposedly hard for the compiler to optimize.For the record a switch case up to 33 choices in the variant (with a function pointer table for >33) is still O(1) in the number of choices in the variant. Not to mention that if somehow abseil generated a switch case for any number of choices in the variant, the compiler would probably just generate a jump table anyway, though of course that's not guaranteed.