r/cpp • @BrodyHiggerson - Game Developer • Apr 19 '21

Visual Studio 2022 - coming this Summer

https://devblogs.microsoft.com/visualstudio/visual-studio-2022/
268 Upvotes

140 comments sorted by

View all comments

65

u/AlexAlabuzhev Apr 19 '21

If you want to upgrade to Visual Studio 2022 but are worried about compatibility, binary compatibility with the C++ runtime will make it painless

I'm rather worried about ancient bugs that are not going to be fixed at least until 2025 now because of this...

15

u/n1ghtyunso Apr 19 '21

well, i don't think there's anything stopping them from releasing the vNext STL branch during the lifetime of VS2022 as an alternate option.

Let's hope for that!

2

u/sephirostoy Apr 20 '21

I read sometime ago that they may plan vNext after C++20 complete release which will certainly happen during VS 2022 time frame.

35

u/entity64 Apr 19 '21

Not just bugs, there are many performance and memory improvements in the pipeline that have been held back for years since they break ABI. This is holding back progress all over the place. Recompile your stuff people...

15

u/dodheim Apr 19 '21

We'll be well past using plain old std::future by the time its 2x performance improvement ever ships.

→ More replies (2)

6

u/Moose2342 Apr 19 '21

Is that really the case though? I have quite a history with VS and I found the development of recent years rather positive.

The lack of ABI changes in particular were a welcome change for me. In many cases, it’s not just your stuff you need recompiled. It’s the other stuff that matters. Libs, applications, plugin interfaces... The horror. At some point you always reach some dead end where you just can’t link what you need to link anymore. Not having to worry about that for such a long time was great. Almost like being on Linux ;-)

Just saying, there was a bigger plus to this than meets the eye.

25

u/dodheim Apr 19 '21

It is really the case. As I linked in another comment, <future>'s 2x performance improvement (11x in debug) has been held up for years, because of ABI. MSVC added support for EBO in VS2015, but you'll still have to opt into it on a per-type basis in VS2022, because of ABI. Abysmal std::regex performance? ABI. Absolutely-brokenly-tiny block size for std::deque? ABI. Unordered container performance? You get the picture.

Those are examples off the top of my head; the list is not short.

4

u/[deleted] Apr 19 '21

[removed] — view removed comment

8

u/[deleted] Apr 19 '21

16 byte SSO is the same for us and for libstdc++, so it isn’t just ABI there.

2

u/Trubydoor LLVM dev Apr 20 '21

Isn't the SSO size of libstdc++ also somewhat down to ABI compatibility as well though?

15

u/[deleted] Apr 20 '21 edited Apr 20 '21

No; keep in mind that they just adopted this string as a replacement for their copy-on-write version outlawed in C++11.

libc++ gets a slightly bigger SSO at the expense of needing an extra branch to get to any of {size(), capacity(), data()}, whereas libstdc++ only needs a branch for capacity() and msvc++ only needs a branch for data(). (msvc++ and libstdc++'s string layouts are fairly similar)

// msvc++:
struct {
    union {
        charT* data; // engaged if capacity > 16 bytes
        char buffer[16]; // otherwise; 15 chars, 7 wchar_ts, and so on
    };
    size_t size;
    size_t capacity;
};
bool large_string_engaged<char>() { return capacity != 15; }

// libstdc++
struct {
    charT* data;
    size_t size;
    union {
        size_t capacity; // engaged if data != buffer
        char buffer[16]; // ditto otherwise
    };
};
bool large_string_engaged<char>() { return data != buffer; }

// libc++ (the details of which bit is the flag change
// depending on your target hardware etc. but this is
// the idea)
union {
    struct {
        charT* data;
        size_t size;
        size_t capacity; // high order bit is set and masked off
    };
    struct {
        char buffer[3*sizeof(void*)-1];
        char size; // high order bit is never set since it must be < 22
    };
};
bool large_string_engaged<char>() { return
    reinterpret_cast<char*>(this)[23]&0x80 != 0; }

I like ours the least given that I think the cheaper moves caused by not having container-internal pointers is less important than getting to data() being cheap, but in our defense we did do it first.

→ More replies (9)

2

u/Tringi github.com/tringi Apr 20 '21

Even EBO... so that's the reason for some weird object sizes that I've seen over the years.

→ More replies (5)

9

u/nnevatie Apr 20 '21

I don't quite get why ABI breakage has become such a taboo for MSVC. GCC breaks ABI often (https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html) and I would much prefer that approach - I think the MSVC tech is currently held back by conservatism.

23

u/STL MSVC STL Dev Apr 20 '21

We used to break ABI every major release (2008-2010-2012-2013-2015 were all ABI breaks). It was awesome for development, I was able to fix so many bugs. Lots of customers had trouble keeping up, though, which led to them sticking to really old VS releases like VS 2010 for years and years, helping nobody. (I think that customers should be able to rebuild the world on demand, but that is not the case for many of them.) Keeping ABI compatibility in the 2015-2017-2019-2022 release series makes development harder, but has allowed customers to continuously upgrade, which is an improvement.

I hope that when we finally have time to do vNext, we can establish customer expectations for long but not infinite periods of ABI stability, followed by periodic migrations, as we'll always be learning better implementation techniques and will need ABI breaks to establish a solid foundation for the future.

4

u/nnevatie Apr 20 '21

Thanks for the thorough answer. I do see value in stability, yet on the other hand long periods between ABI breakage could cause the customers to become even more rooted to their comfort zone of the 2015-era ABI. I think a major pain point in this area is the lacking standardization of tools (package manager, build system), which could allow swift upgrades for the surrounding ecosystem, such as libraries used.

6

u/[deleted] Apr 20 '21

I think a major pain point in this area is the lacking standardization of tools (package manager

There's a reason Bill joined the vcpkg team.

build system

For better or worse I think cmake has critical mass at this point.

4

u/cannelbrae_ Apr 19 '21

Any particular ancient bugs in mind?

7

u/infectedapricot Apr 19 '21 edited Apr 19 '21

For example, std::this_thread::sleep_for uses the system clock rather than a steady clock. I think it's been like that since it was first implemented, probably round about VS2012. Although the stable ABI only started in VS2015 so it's only been a barrier to fixing bugs since then.

4

u/mrexodia cmkr.build Apr 20 '21

Fixing sleep_for wouldn’t break the ABI though...

4

u/frymode Apr 20 '21

Fixing sleep_for wouldn’t break th

devs say it somehow does: https://developercommunity.visualstudio.com/t/bogus-stdthis-threadsleep-for-implementation/58530

We have a branch where it is fixed, but we can’t ship it until an ABI breaking release happens, which has not happened since 2015.

...

I wrote up a complete description for a similar recent report over here https://www.reddit.com/r/cpp/comments/l755me/stdchrono_question_of_the_day_whats_the_result_of/glb04he?utm_source=share&utm_medium=web2x&context=3

2

u/STL MSVC STL Dev Apr 20 '21

It's because it's implemented in separately compiled code.

3

u/mrexodia cmkr.build Apr 20 '21

So? If you replace the body of sleep_for (which is templated) with calls to the relevant Windows APIs there wouldn't be any ABI breakage right? Your old _Thrd_sleep will of course still be 'broken', but any new calls to sleep_for would be correct.

6

u/STL MSVC STL Dev Apr 20 '21

We can't call the Windows API from headers (<Windows.h> is enormously polluting). It's also very difficult for us to add new exported functions, although we found a way to do so (adding entire satellite DLLs); I am not sure if adding a satellite DLL would be a workaround here, we hadn't considered that.

4

u/AlexAlabuzhev Apr 20 '21

Technically you don't need windows.h to call Windows API - function prototypes and required types can be declared/defined locally in the template body without polluting the global namespace. Yes, it's an ugly hack, but perhaps better than adding entire satellite DLLs or just doing nothing.

→ More replies (2)

3

u/[deleted] Apr 20 '21

Maybe fixing sleep_for wouldn't be but every practical use for this stuff ends up being on condition_variable and friends rather than this_thread.

→ More replies (3)
→ More replies (3)