Динамический полиморфизм против std::variant на указателях: Разрушаем мифы о скорости std::visit

В экосистеме современного C++ прочно укоренилось мнение: классический динамический полиморфизм через виртуальные функции ( vtable ) — это устаревший, медленный и недружелюбный к кэшу процессора механизм. В качестве «серебряной пули» модно предлагать связку std::variant и std::visit . По интернету кочуют статьи, утверждающие, что std::visit выполняет диспетчеризацию за фиксированное время O(1) и полностью уничтожает старый добрый ООП-подход. Но в таких сравнениях авторы часто совершают методологическую ошибку: они противопоставляют вектор указателей std::vector<Base*> вектору сырых объектов std::vector<std::variant> . Разумеется, std::variant побеждает, но не из-за механики вызова, а благодаря стопроцентной локальности данных в кэше процессора. Давайте снимем розовые очки, уравняем условия и изолируем саму механику вызовов. Представьте реальный сценарий: объекты тяжелые, создаются динамически в разное время и разбросаны по куче (Heap), а мы оперируем массивами их адресов. Мы столкнем лоб в лоб std::vector<Base*> и std::vector<std::variant<TypeA, TypeB, TypeC>*> в условиях раздельной компиляции (когда оптимизатор -O2 не видит тела функций и не может применить тотальный инлайнинг).

https://habr.com/ru/articles/1045494/

#динамический_полиморфизм ++ #cplusplus #visit #variant

Динамический полиморфизм против std::variant на указателях: Разрушаем мифы о скорости std::visit

В экосистеме современного C++ прочно укоренилось мнение: классический динамический полиморфизм через виртуальные функции ( vtable ) — это устаревший, медленный и недружелюбный к кэшу процессора...

Хабр
Canadian MPs plan Taiwan visit as Beijing says trip ‘hurtful’ to ties
MP Judy Sgro, chair of the Canada-Taiwan Parliamentary Friendship Group, told The Canadian Press Liberal and Conservative MPs will visit the island the week of Oct. 11.
#Canada #Politics #World #China
https://globalnews.ca/news/11895936/canadian-mps-taiwan-visit-beijing-says-trip-hurtful-to-ties/
Canadian MPs plan Taiwan visit as Beijing says trip ‘hurtful’ to ties
MP Judy Sgro, chair of the Canada-Taiwan Parliamentary Friendship Group, told The Canadian Press Liberal and Conservative MPs will visit the island the week of Oct. 11.
#Canada #Politics #World #China
https://globalnews.ca/news/11895936/canadian-mps-taiwan-visit-beijing-says-trip-hurtful-to-ties/
Canadian MPs plan Taiwan visit as Beijing says trip ‘hurtful’ to ties
MP Judy Sgro, chair of the Canada-Taiwan Parliamentary Friendship Group, told The Canadian Press Liberal and Conservative MPs will visit the island the week of Oct. 11.
#Canada #Politics #World #China
https://globalnews.ca/news/11895936/canadian-mps-taiwan-visit-beijing-says-trip-hurtful-to-ties/
Pope Leo gives Spain’s 'phoenix' prime minister another turn in the global spotlight
Pope Leo XIV’s historic visit to Spain has again thrust the country into the global spotlight, underscoring the pontiff’s alignment with Spanish Prime Minister Pedro Sánchez’s progressive policies on migration.
https://www.cbc.ca/news/world/pope-leo-spain-prime-minister-9.7227110?cmp=rss
Pope Leo gives Spain’s 'phoenix' prime minister another turn in the global spotlight
Pope Leo XIV’s historic visit to Spain has again thrust the country into the global spotlight, underscoring the pontiff’s alignment with Spanish Prime Minister Pedro Sánchez’s progressive policies on migration.
https://www.cbc.ca/news/world/pope-leo-spain-prime-minister-9.7227110?cmp=rss
Woman questions Janeway security after strangers allegedly stole items from her family’s room near ICU
A Newfoundland and Labrador woman says she no longer feels safe visiting her stepson at the Janeway Children's Hospital after three strangers entered her family's room.
https://www.cbc.ca/news/canada/newfoundland-labrador/janeway-room-safety-violated-9.7225004?cmp=rss
Chinese leader Xi Jinping to visit North Korea for first time since 2019
The announcement of the trip came a day after North Korea unveiled a new facility to produce the material for nuclear bombs.
https://www.cbc.ca/news/world/xi-jinping-north-korea-visit-9.7224477?cmp=rss
Chinese leader Xi Jinping to visit North Korea for first time since 2019
The announcement of the trip came a day after North Korea unveiled a new facility to produce the material for nuclear bombs.
https://www.cbc.ca/news/world/xi-jinping-north-korea-visit-9.7224477?cmp=rss