Boost logo

Boost :

From: Alexander Grund (alexander.grund_at_[hidden])
Date: 2024-05-28 10:54:48


>> Performance:
>>
>> You already have #248 about a performance regression in flat_map. It can
>> currently be twice as fast to use a struct { int key; mutable int value;
>> } in a flat_set than a flat_map<int,int>.
>> I would prioritize fixing known performance issues before looking for
>> others, but I guess it is a worthy goal.
>
> Yes, I previously was using type-punning to be able to use memcpy in
> flat_map when key and mapped_type were trivial, but compiler warnings
> and some suspicious aliasing issues were reported, so I had to
> roll-back. I'll need to revisit this, I'm not sure if other flatmap
> implementations (chromium, folly...) perform some type of type punning
> to achieve the speedup.

I have seen Abseil using a union of `pair<K,V>` and `pair<const K, V>` for flat_map nodes. However that had led to misoptimzation due to alias violations on some systems and GCC
See my Issue there for a technical analysis from some time ago: https://github.com/abseil/abseil-cpp/issues/975>

As usual: While type-punning with UB might work in most cases, there will be failures in some. And there the UB was non-obvious at all.

Alex


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk