public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99386] New: std::variant overhead much larger compared to clang
@ 2021-03-04 12:34 mail at milianw dot de
  2021-03-04 13:12 ` [Bug c++/99386] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: mail at milianw dot de @ 2021-03-04 12:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99386

            Bug ID: 99386
           Summary: std::variant overhead much larger compared to clang
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mail at milianw dot de
  Target Milestone: ---

I've come across some code in an application I'm working on that makes use of
std::variant. The overhead imposed by std::variant compared to a raw type is
extremely high (700% and more). I created a little MWE to show this behavior:

https://github.com/milianw/cpp-variant-overhead

To reproduce, compile two versions in different build folders with both g++ or
clang++:

```
CXX=g++ cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo
CXX=clang++ cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo
```

Then run both versions:
```
perf stat -r 5 -d ./variant 0
perf stat -r 5 -d ./variant 1
perf stat -r 5 -d ./variant 2
```

I put the measurements on my machine into the README.md. The gist is, the
relative runtime overhead is huge when compiling with g++:

g++
uint64_t: 100%
std::variant<uint64_t>: 720%
std::variant<uint64_t, uint32_t>: 840%

clang++
uint64_t: 100%
std::variant<uint64_t>: 114%
std::variant<uint64_t, uint32_t>: 184%

The baseline for both g++/clang++ is roughly the same.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-03-04 14:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-04 12:34 [Bug c++/99386] New: std::variant overhead much larger compared to clang mail at milianw dot de
2021-03-04 13:12 ` [Bug c++/99386] " rguenth at gcc dot gnu.org
2021-03-04 13:48 ` mail at milianw dot de
2021-03-04 13:52 ` mail at milianw dot de
2021-03-04 14:08 ` mail at milianw dot de
2021-03-04 14:49 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).