← Back to context

Comment by shrimp_emoji

10 months ago

> C++ has them off by default for std::vector because c++ is designed by and for the utterly insane.

And for those who value performance and don't want to pay the cost of "a lot more than 1-2%" ;p

The data I've seen for turning on bounds checks in std::vector shows overhead considerably lower than 1-2%.

std::vector falls into the category of things that are easy to bounds check, st the cost, even under today's primitive compilers, is low. It's direct pointer accesses—which are common in c but not in c++ or most other languages—that are hard to and therefore cost more to bounds check.

  • That's assuming you're keeping no metadata about your C array(s) that you're bounds-checking, which would be very slow indeed. :o You'd be traversing pointers until you hit a tombstone value or something. But would anyone do this in performance-chasing code? Cuz, otherwise, with metadata to support your bounds checks, you're doing the same thing that I assume std::vector is doing: asking your array metadata about whether something's in bounds. And that's extra cycles, which can add up depending on what you're doing!

    Btw, in my experience, std::vector is fast. Insanely fast. "I don't understand how it can be so fast", "barely distinguishable from raw arrays in C" fast. Not doing bounds checking is probably part of that, though far from the whole story.

std::regexp, std::map, fronzen ABI.... apparently the value for performance is relative at WG21.