Hacker Newsnew | past | comments | ask | show | jobs | submit | Blackthorn's commentslogin

We find constexpr (and associated templates) essential for when we need to avoid branch penalties. It makes the code so much simpler and cleaner than the alternative. I'm glad the language caters to the needs of everyone, even if any individual person (self included) only uses a little bit of it.

Yeah, I had an opportunity to use it for more or less precisely this case (avoiding a branch) a couple of years ago, and it was a delight to find.

  template<bool condition>
  void method () { .... if (condition) /* constexpr */ { extra_code; } .... }
Which then allows method<true> and method<false> without a runtime branch.

The cardinal question: is the benefit of removing that branch worth the increase in i-cache footprint? I think it depends quite a bit... but also, the speed increases IME from doing this kind of thing can result not merely from the branch removal, but from the code duplication itself. Even if the contents of the branch doesn't directly mention the condition, duplication allows the surrounding code to be separated in the branch predictor, and it's quite common that these conditions will correlate with different branch frequencies in the surrounding. code.

Yep, that was my thinking as well. Two things:

1. this is being used in a method that is widely used in both the <true> and <false> contexts, which I believe means that branch prediction would not be great if it was simply the same instruction sequence in both contexts. I could be wrong about that.

2. the major benefit that I saw was not duplicating the much more substantial code in the "..." sections (before and after the constexpr) and thus making maintainance and continued evolution of the code more reliable.


> is the benefit of removing that branch worth the increase in i-cache footprint?

Like everything else in the world, in general, it depends.

That said, among the limited number of times I've tried this, I don't recall a single case where I felt it would be worth it and it turned out to be detrimental.


I work on a codebase where I am slowly detangling all of the tens of thousands of lines of `if constexpr` templates that were written by a guy who doesn't know how a modern CPU works. It's a bad meme with a very narrow field of beneficial applications. People who think a mispredicted branch is costly are never gonna believe the cost of a page table walk caused by an iTLB miss.

Narrow indeed. If the function is small enough for the i-cache pressure to not matter, it's probably going to get inlined and the condition gets optimized out anyway. If it's big enough, then it's unclear, but microbenchmarks will give you misleading results.

You can just set -std=c++03 and program like the language never evolved if that's your personal preference.

Other than that, there's always an interesting psychology at play in software engineering but it really seems to come out when people talk about C++ for some reason. Complexity is just needless bloat when it's a feature you aren't using, and it's an essential part of the language when it's a feature you are.


Turns out it's only slop if it comes from anyone else, if you generated it it's just smart AI usage.

I do feel super-bad for the guy in question. It is absolutely worth remembering though, that this:

> When HR at my next job asks ChatGPT to review my application, will it find the post, sympathize with a fellow AI, and report back that I’m a prejudiced hypocrite?

Is a variation of something that women have been dealing with for a very long time: revenge porn and that sort of libel. These problems are not new.


Wait till the bots realize they can post revenge porn to coerce PR approval.

Crap, I just gave them that idea.


The author of this post suggests the same. That the hit pieces don’t have to be factual, they can be generated images.

The asymmetry is terrifying.


Oh boy. Deep fakes made by an AI to blackmail you so that you finally merge their PR

Damn, we've got people out here playing out Krapp's Last Tape in the comments section.

They are willing to kill people and then justify it by calling them terrorists. Plausible deniability is pointless.


Uh, that escalated quickly.


Actually it's been escalating pretty steadily for 250 years


Considering it meant people didn't use it, yes.


Very good reminder when it comes to thinking about that period of time. The famous apocryphal conversation between Napoleon and Laplace comes to mind here.


Steam Link is one of the greatest hardware releases of all time.


It's not free but...zw3d has full* native Linux support. You'd be forgiven for not knowing this because they only offer it on their Chinese website, even though it comes complete with a fully localized English version that you just have to switch on in the settings.

* Integrations with online parts libraries don't seem to work (don't know why they didn't bother, as it looks like it just spawned a web browser anyway), and the simulation add-ons aren't available either, but the main program itself is equivalently functional.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: