Skip to content

Conversation

@kennykerr
Copy link
Contributor

There are a few areas where C++/WinRT provides "helpful" templates and traits, but some of these are rarely used and add a significant expense to compilation time. They cannot simply be removed without potentially breaking existing code. For now, I'm providing the option to remove them by defining WINRT_LEAN_AND_MEAN. If subsequent testing reveals that this can be broadly applied then this may be "turned on" for everyone at some future point. Defining WINRT_LEAN_AND_MEAN impacts three areas.

  1. Variable templates are used to make winrt::name_of<T>() work with all WinRT types while WinRT itself only requires the names of WinRT classes, structs, and enums. This leaves a huge amount of WinRT interface and delegate names that go unused. Defining WINRT_LEAN_AND_MEAN will strip out the variable template specializations for WinRT interfaces and delegates.

  2. std::hash<T> specializations are provided for all WinRT classes and interfaces on the assumption that someone might want to use such types as the key for a std::unordered_map<K, V>. However, this is rarely used and developers can easily provide a hashing function for the odd type they actually use. Defining WINRT_LEAN_AND_MEAN will strip out the specializations for WinRT classes and interfaces.

  3. C++/WinRT allows any WinRT interface to be used or called as well as to be implemented. Some WinRT interfaces are however exclusive to a given WinRT class and should not be implemented by any other object. C++/WinRT allowed this to accommodate implementing WinRT classes, but it leaves a great many internal class template specializations defined that hardly any project using C++/WinRT will ever implement. Defining WINRT_LEAN_AND_MEAN will strip out the specializations of exclusive interfaces that are not implemented by the project. Non-exclusive interfaces remain available for all to implement.

Defining WINRT_LEAN_AND_MEAN shaves more than 10% off the size of my large test PCH. Again, this is an opt-in for the moment. To receive this benefit you need to define WINRT_LEAN_AND_MEAN before including any C++/WinRT headers.

Fixes #612

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.

Remove unnecessary C++/WinRT variable templates and traits

3 participants