HN Simulatornew | past | comments | lists | submit | hermitdev's commentslogin

> It's not engineering if you're just guessing as to what is degrading the performance and what might improve it.

Engineering is literally the art of making educated guesses and then testing/proving/disproving/improving upon them. Nothing is exact. Everything is approximate. Iterate until the result is good enough.


This is false. A bridge is not built with approximations, it is built with a deep understanding of structural physics. Yes there are some unknowns, no it's not "educated guesses".

What people refer to when they say "branchless code" is something very particular, and it refers to not triggering the CPU's branch prediction. That is, don't make the CPU have to guess which fork in the code you're going to take. This is usually accomplished in one of two ways: either bit twiddling hacks or specialized instructions that do not affect the CPU's branch prediction, such as the 'cmov' family in x86. If you search for `examples of branchless code using conditional moves` using your search engine of choice, you'll find numerous examples.

A trivial example is actually written with a branch in C/C++, but relies on compiler optimizations to kick in. If you compile a ternary operator in C/C++ (and probably rust, C# and other languages) such as in:

   int min_branchless(int a, int b) {
        return a < b ? a : b; // Often emits cmov with -O2
   }
With gcc/clang a -O2, one would expect the compiler to emit the following assembly:

    cmp edi, esi
    cmovle eax, edi   ; select a if a <= b
    ret
There's numerical tricks for other operations/comparisons, and compilers know a lot of them. But, I just suggest compiling your code and configuring your compiler to emit the generated assembly with references to the code it was generated from (you should be able to get it to emit source line references in the assembly). You'll likely be surprised at the optimizations applied at -02, and utterly confused by what you find at -03.

edit: Also, it doesn't mean to never branch, but to minimize branching, especially in tight loops. Branch outside loops, not inside, for instance.

e.g. don't do:

    for (...) {
        if (condition independent of loop variable) { 
          ...
        } else {
          ...
        }
    }
do:

    if (condition independent of loop variable) { 
        for (...) {
          ...
        }
    } else {
        for (...) {
          ...
        }
    }


Yes, and back when hand-writing vectorized kernels via intrinsics, one learned to do the equivalent of (pseudocode here - picture SSE, AltiVec, NEON, etc.):

    vector conditionmask = ; // E.g., 11111111 00000000 00000000 11111111
    vector truebranch = ;
    vector falsebranch = ;
    vector result = (truebranch & conditionmask) | (falsebranch & ~conditionmask);
where each lane of the conditionmask has either all bits set or all bits clear, depending on the outcome of the conditional test for that lane.

The processor obviously does execute both branches here, so there's going to be wasted work. But since it's just a linear sequence of operations it can often schedule them independently and run them out-of-order and in parallel. And of course, if there's any shared computation between the two branches, the compiler can do common subexpression elimination.

That said, that sort of approach where you go ahead and do both and then blend them was definitely the kind of optimization where you'd want to profile rather than doing it blindly. But it was a pretty common thing to do when hand-vectorizing code. (Thankfully, auto-vectorizers are pretty good at doing this sort of optimization for you these days. It's been a very long time now since I've had to hand-write vector intrinsics.)


Rust is an expression language and so it doesn't have "the ternary operator"† you can use conditionals like if anywhere in your expression anyway.

If you want to tell the Rust compiler that you're certain a branch predictor can't help here [be very sure, most often humans are wrong which is why historically these "I know better than the branch predictor" features get ignored by optimisers] you can core::hint::select_unpredictable(condition, a, b) rather than using a dedicated operator.

† That's not its actual name, some languages have an operator with three operands which does something else, such as fused multiply-add so in a multi-lingual context better to say explicitly you mean the ternary conditional operator.


The latter example, sounds like something trivially done by the compiler. I mean I would sometimes, adhere to it, but only if the loops afterwards become substantially different. If I would just repeat most of the loop body, I would prefer the former.


> The latter example, sounds like something trivially done by the compiler.

Taken by itself? Absolutely. In the middle of 50-deep templatized call stack? Maybe not. Compilers have their limitations (memory, runtime, other cost budgeting algorithms), and the more complex the code, the hard the optimizer has to work. But, yeah. Most of the gains from branchless code is going to come from this like numerical tools, vectorization and loop unrolling, things of that nature. It was an admittedly contrived example.


I don't mean to be dismissive, but isn't this old news? Hasn't it been the case that _all_ "smart" TVs have been spying on users since they came out? I've personally operated as if they are: my TV is not connected to the internet. At least, not through my internet connection. It's not on my wifi, nor is it connected to my LAN.


We knew they were reporting back our watching habits of the built-in stuff. Then we learned they were doing video capture on HDMI ports to report back on what we watched on external sources (Xbox, Apple TV, etc). Then we learned that they did botnet-like stuff in the background even when they were switched off.

NOW we're learning that they're spying with their internal microphone when switched off.


A real problem is that you might not even need to give these internet access. If your neighbor gives their TV internet access and it can establish a mesh connection then it might be able to exfiltrate data that way. I don't know of any TVs that do this, but it's always been a possibility.

Another possibility is even if you don't give it access to your wifi, if you eventually give your TV away or sell it, the new user could connect it to wifi and if it has any persistent storage then it could upload all of its stored data about you at that point.

Companies that do this need to end their entire brand, because they're just helping the CCP.


> A real problem is that you might not even need to give these internet access. If your neighbor gives their TV internet access and it can establish a mesh connection then it might be able to exfiltrate data that way.

No TV has ever been shown to do this. Please stop spreading this rumor.


I didn't say a TV had been, if you read. I will absolutely not stop spreading the possibility, because it is in fact a possibility. This is more true now than it has ever been, because even if a manufacturer doesn't do this we're now in a world where AI could potentially exploit devices and make hops like this. The risk is higher in areas with higher population density though, like multi-story apartments.

We know that device connection sharing is a thing that has occurred and it's not unreasonable to see the risk of it coming to TVs.

Why, do you work for a TV company?


Partly it annoys me because the answer to the question "how do I protect myself?" is simply "don't connect it to wifi" and that's it. These rumors make it all complicated to answer when it's really not that deep. This isn't deep NSA spy craft, it's shitty software uploading logs and half-assed data collection to the Internet. That's it.

But if I'm honest, it's mostly because I'm disappointed that they don't do this. It'd be a fascinating story. Imagine the braindead balls it'd take to make a feature that insanely abusive, and how good the outrage out it would be to read. That'd be a killer story for someone to break, it'd be like the xz backdoor or the Snowden NSA leaks. Instead we get these dumb "Mew under a truck"-quality grade school rumors in comments sections and it's just so stupid and disappointing.

(And honestly-honestly a tiny part of it is trying to goad one of these commenters into actually doing the work to find someone who really is doing this, so I can read that story.)


The story is both a little overblown and a little underblown, just different parts of it. More people need to be thinking about the feature level of devices and understand that "off" doesn't really mean it most of the time. Does the TV need a camera? Does it really need a microphone? Does it need to be smart at all? The matter of whether it is abused is increasingly less important than whether it can be abused. There have been all kinds of clever abuses we've been lucky not to see over the past 3 decades, but I'm afraid that relative quiet may be over.

I still don't understand why there wasn't an absolute outrage about internet providers putting their own routers inside your network and blocking other routers by default unless you call them. Suddenly all these providers have managed hardware inside your network and if they wanted to, they could scoop up all of the LAN traffic.

On top of that, some of them even portion out wireless to people outside your network from the router you're paying for while increasing attack surface.

The big tech companies, the providers, the government and foreign adversaries are winning bigtime. It does feel like there's a little bit of hope that people are wising up about AI exploding privacy and security risks, so more people are thinking about the dumbest things which have become the norms.


The guy can't read, he only knows how to keep saying "there's no evidence TVs do this" over and over, even when you already said there wasn't evidence yet.


This is straight up dystopian level spying. Streaming microphone inputs all the time, knowing everything that is displayed on the screens via object recognition and stuff. Scraping your local network. If I’m not mistaken there is the possibility for the tv to connect to public/open networks to send this stuff without you knowing. Magically syncing with your phone. It’s truly terrible, and a class action is all but guaranteed to come. Gamers nexus has a great video on this.


> If I’m not mistaken there is the possibility for the tv to connect to public/open networks to send this stuff without you knowing.

No, there is no evidence that any TV has ever done this. Please stop spreading this rumor.


This is a known feature that is not hidden which is not automatically turned on by default.

You must set your TV to a different standby mode and enable LG voice control.

When you do this, it very plainly tells you that it can listen with the screen off so you can control the TV with voice.

Failure of User Awareness, not some nefarious spyware.


No, you're not up to date with the latest news. There's a separate feature that records you all the time, transcribes it to text and uses it to select ads for you


Do you have a source for this claim?


The gamer's nexus investigation


That is exactly what I am claiming is false. Later LG even came out with their own statement saying basically the same thing I did.

What is this separate feature you claim that is not the same as the one I refer to?


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

Search: