This weird trick, which the C++ committee doesn't want you to know, will reduce your application size by half and improve performance: -fno-exceptions
-
-
I'd say my code is pretty robust, however, I don't use the stl. I agree, though, using the stl without exceptions is not exactly robust.
-
STL error interface is horrid. Simple containers like std::vector and std::map are unusable. Implementing Allocator and querying state after calls that might allocate is very unfriendly. -nostdlib -fno-exceptions -fno-rtti -lc extern "C" void __cxa_pure_virtual() { abort(); }
-
STL is, in many ways, horrid. Writing exception safe code is hard. Writing fast exception safe code is impossible. The containers have so many performance pitfalls with exceptions enabled. I like to reason about code by looking at it. PS: std::map should never be used anyways.
-
What performance pitfall exists when an exception is not thrown?
-
Create a struct with a copy or move constructor. Put a printf inside. Put it into a vector. For every resize, every push_back, they will be called twice.
-
push_back has to copy only in slow path (not enough capacity), and only to solve cases like push_back(v[5]). Exceptions don’t change that. What they do change is that move ctor has to be noexcept (or type - noncopyable) to be called when vector grows.
-
-fno-exceptions removes the case that your move ctor has to be noexcept. And I'm not saying anything else. I don't think that's obvious at all. First time I looked at vector in a little more detail I was super confused by this.
-
The reason I mentioned this is you mentioned push_back and I’ve seen STL implementations just copy the input arg in push_back first thing - but they were just leaving perf on the table.
- 3 more replies
New conversation -
-
-
As if STL was usable in high performance projects..
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Believe it or not the committee has started to recognise this as a genuine problem and is looking at solutions: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0709r1.pdf …
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.