C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Dummy value protocol

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Sun, 8 Jun 2025 00:20:56 +0300
On Sun, 8 Jun 2025 at 00:15, Avi Kivity via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Of course I could implement it in my own optional (and other classes - I gave optional as an example but it works for other use cases as well), but then it wouldn't work in the trillions of other optionals in my code (that I can't change) and others' code.
>
>
> I wrote a demonstration [1]. It is written to penalize the standard implementation by having the worst mix of optional and non-optional (but is not cheating in any way). If your machine has a better branch predictor than mine, you may need to increase the vector size (10,000).

Yeah, well, once you have enough data, no branch predictor will save
you from the costs, because if you have a
vector<optional<vector<optional<string>>>>
with lots of elements with any values whatsoever, you're going to end
up paying the branch costs that optional introduces.

With the change you're suggesting, the optionals introduce no
additional branches to the destructor of that beast.

> PS. I'm proposing to change std::optional (so it won't be harder to use).

And that's a behavioral ABI break. We could just as well avoid the
difficulties of that and go with a new type, but I do appreciate
that that wouldn't automatically speed up your existing uses.

Received on 2025-06-07 21:21:09