C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Extension to runtime polymorphism proposed

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sat, 04 Apr 2026 19:44:15 -0700
On Saturday, 4 April 2026 08:52:35 Pacific Daylight Time Muneem via Std-
Proposals wrote:
> Std::visit is proven to be slow in my discussion with mr.thiago, who said
> that we should wait for compiler backends to become faster, which is
> irrelevant because c++ is supposed to have constructs that make it fast on
> an intermediate representation level. It can't even be optimized on an
> abstract tree level and/or dosent provide std::move(variant_obj)

No, we have proven that the difference in performance is negligible and
therefore not an argument.

> The compilers can do optimizations on abstract tree level, but without
> significant overhead, it can't do those on std::visit. At least not to
> counter the fact that move semantics are missing(constructs can't be
> virtual).

Unproven statement again.

And "constructs can't be virtual" is a meaningless statement. std::visit has
nothing to do with virtual calls: it can be used to call virtual functions.
Moreover, the implementation of the visitation can choose to use a jump table,
either by doing it manually like it looks like libc++ does, or by having the
compiler implement it via sequence of if-else chain.

> Your example shows that I mean, compilers convert them into switch case
> statements on a assembly level, not on a abstract tree level. We need a new
> value type to change the value abstract trees work.

Unsubstatiated statements. Why do you think we need a new value type to inform
the AST? Why aren't the current techniques sufficient? What information,
specifically, would compilers readily have available to improve on code
generation that they don't today?

You have not shown the widespread problem you claim exists and more
importantly, you have not shown what the compiler would generate in the
presence of extra information. Half the time I am reading your proposed
solutions, I get the feeling you're assuming compiler magic. You don't seem to
have thought through how the compiler would implement this and the
consequences of it. You'll probably need to prototype the implementation if
you want this to get traction.

> Try moving a polymorphic object using std::move, and you will see how
> widespread the problem is.

Why would I want to do that? There are lots of things that don't work well,
but no one cares because no one wants to use them.

And finally:

> I couldnt sleep because when I close my eyes, tears come which makes pain
> just heat up, so I spent a few hours thinking and combining an answer to
> all your welcomed questions and feedback in one email:

If this discussion is affecting your health, please take a step back and relax.
This thing you're proposing, which no one quite yet seems to understand, is
likely going to take years to be accepted, if it is accepted at all. This is a
marathon, not a sprint.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center - Platform & Sys. Eng.

Received on 2026-04-05 02:44:28