Typical C++ Bullshit (TRIGGER WARNING: contains C++)



  • Premature or mature optimization?


  • Discourse touched me in a no-no place

    Fuck slideshows sideways.



  • make a class the represents a group of objects but that's just using
    classes for their own sake and denying oneself all the other benefits of
    (what I call) array oriented programming. Fantastic compile times,



  • @Buddy said:

    array oriented programming

    I've seen this in the wild, in VB6. It was a wild ride.



  • I don't get where/how float is being converted to int? The post-it note implies it's the if conditions or the return statements. Unless comparison operators (<=, >=) return the same type as they are comparing (which doesn't seem right to me, they should be returning int/bool)



  • Is this supposed to be a joke?



  • @ben_lubar said:

    Is this supposed to be a joke?

    No - it's Mike Acton, and I'm relatively sure he's serious. See e.g., his CppCon keynote.

    IMO most of his points have a some valid ground, but whether or not they are applicable to the example (I've seen it before), is questionable. There's simply a lack of information (profiling, rest of code base). On the other hand, IIRC, the original author of the code is asking people to help him optimize it, so... meh. He gets what he's asking for, I guess?

    (Again IMO, I agree with the issue about designing code around single elements, rather than efficiently handling many of them - if you typically have a lot of elements/objects anyway. The latter is hard, and will make a mess of your code unless you design towards that from the get-go.)



  • @Spencer said:

    I don't get where/how float is being converted to int? The post-it note implies it's the if conditions or the return statements. Unless comparison operators (<=, >=) return the same type as they are comparing (which doesn't seem right to me, they should be returning int/bool)

    Yeah, not quite sure what's going on there. Without knowing the target hardware, it's probably a bit hard to guess at. My initial guess is that you could return the result as a float (i..e one of -1.0, 0.0, 1.0) rather than an int, which eliminates a conversion if you use the result in arithmetic later on. Not really seeing that in the above code, though.

    Another possible concern, if this were CUDA-like code, would be that you're "wasting" a GP-register to hold the result, where as if you defer the comparisons to where ever you actually need it, you could keep the result of the compare in a predicate-register and thereby possibly lower the register pressure.


  • Discourse touched me in a no-no place

    @FrostCat said:

    Fuck slideshows sideways.

    Having said that, I'm only opining on the presentation, not the content.



  • Yeah. Seconded.

    Filed under: Wooden table missing



  • @cvi said:

    On the other hand, IIRC, the original author of the code is asking people to help him optimize it, so... meh. He gets what he's asking for, I guess?

    He asked for help optimizing, he didn't ask for people to be complete dicks to him.


  • ♿ (Parody)

    @JoeCool said:

    He asked for help optimizing, he didn't ask for people to be complete dicks to him.

    That's just optimizing the interaction, since they skipped all the boring parts where they ask questions and he has dumb answers.


  • Banned

    While that guy who made the slides (slides, because viewing it as slideshow doesn't work for me) did a good job pointing out faults in code, he totally failed at why this is wrong. Instead of #swag, the post-it notes and terrific mental shortcuts made him look more like total asshole. The "array oriented programming" made me laugh; instead of making up your own terms, check if someone else hasn't already established a name for your thing and got widespread adoption.

    @people here: you might think this if/else/return int thing might not be such a big deal, but this little snippet would be probably ran billions of times per second. Getting 40 instead of 50 cycles here matters.



  • I don't understand what he means by sorting the data on slide 30. Is he really saying that the correct way is to sort based on planeState and then only operate on valid planes? Am I wrong in thinking that sorting (n log n) would be slower than making one pass through the data and filtering based on valid data (n)?

    Then again, I'm completely ignorant of cache and other hardware issues (and what LHS and PPU refer to), so I'm probably missing basic things.



  • @cvi said:

    Yeah, not quite sure what's going on there. Without knowing the target hardware, it's probably a bit hard to guess at. My initial guess is that you could return the result as a float (i..e one of -1.0, 0.0, 1.0) rather than an int, which eliminates a conversion if you use the result in arithmetic later on. Not really seeing that in the above code, though

    Conversion? Unless OUT/IN/NONE are floats, there's no conversion. (I'd use an enum instead...)
    And I'm pretty sure (too lazy to look it up, caffeine needed) that if s.r is an int, it will convert to a float.
    So I see no float->int conversion here...


  • kills Dumbledore

    @MZH said:

    LHS

    Left Hand Side?

    @MZH said:

    PPU

    Physics Processing Unit?


  • BINNED

    @boomzilla said:

    That's just optimizing the interaction, since they skipped all the boring parts where they ask questions and he has dumb answers.

    You forgot the part where he finds reasons to reject all of the given suggestions.



  • Load Hit Store and PowerPC Processing Unit.. both PlayStation3-isms. Those slides are from 2008, so this was relevant to optimal programming on that platform and more generally cell-based programming, something Mike (a former co-worker) was hot to analyze and write about back then ( http://cellperformance.beyond3d.com/articles/index.html ).


  • Banned

    @MZH said:

    I don't understand what he means by sorting the data on slide 30. Is he really saying that the correct way is to sort based on planeState and then only operate on valid planes? Am I wrong in thinking that sorting (n log n) would be slower than making one pass through the data and filtering based on valid data (n)?

    You sort once, and iterate over and over again.

    @dcon said:

    Conversion? Unless OUT/IN/NONE are floats, there's no conversion. (I'd use an enum instead...)

    I think that asshole considers a code that takes float and returns int a conversion. It would probably be more optimal if it just returned the original value, or one of -1.0, 0.0, 1.0. Remember, on the low level, everything is a set of bytes - the only thing that matters is if it's loaded to CPU (where it's treated as int) or FPU (where it's treated as float). No enums, no objects, no nothing - just int or float.



  • This is dated 2008-7-15

    wtf man.


  • Discourse touched me in a no-no place

    @Gaska said:

    you might think this if/else/return int thing might not be such a big deal, but this little snippet would be probably ran billions of times per second. Getting 40 instead of 50 cycles here matters.

    Usually, the interaction with the CPU cache and memory fetch predictor matters more than anything else. Code that works well with those goes much faster than a simple count of cycles would lead you to expect. Measure, don't guess.


  • Banned

    I know, I know. But think what would happen if int assignment took 2 cycles instead of 1. Also, you forgot branch prediction on your list of unobvious CPU features.



  • @cvi said:

    IMO most of his points have a some valid ground, but whether or not they are applicable to the example (I've seen it before), is questionable. There's simply a lack of information (profiling, rest of code base). On the other hand, IIRC, the original author of the code is asking people to help him optimize it, so... meh. He gets what he's asking for, I guess?

    Agreed. I would be hesitant to sacrifice a clean design in the name of performance unless there were compelling metrics in favor of it.

    @Gaska said:

    The "array oriented programming" made me laugh; instead of making up your own terms, check if someone else hasn't already established a name for your thing and got widespread adoption.

    Interesting stuff. Towards the end, it seemed like the author was simultaneously advocating a relational model and saying that such a model is a bad fit for the domain. I could see some advantages to having a more set-based architecture. At the same time, I would wonder how those advantages compare to OOP's standard advantages of encapsulation, separation of concerns, etc.

    @Gaska said:

    @people here: you might think this if/else/return int thing might not be such a big deal, but this little snippet would be probably ran billions of times per second. Getting 40 instead of 50 cycles here matters.

    This is true, but he paints with a very broad brush. While, for example, virtual methods might not be a good idea in the code in question, it's a pretty hasty generalization to say that a "'good' use is hard to come by" and throw dynamic polymorphism is out the window altogether.



  • @Matches said:

    This is dated 2008-7-15

    wtf man.

    They're still working on that neural browser interface, so I sadly haven't been able to read every single blog post on the Internets as it was published in a timely manner. Instead, I read them as I encounter them. I hope you'll understand.

    @Jim_Buck said:

    Load Hit Store and PowerPC Processing Unit.. both PlayStation3-isms. Those slides are from 2008, so this was relevant to optimal programming on that platform and more generally cell-based programming, something Mike (a former co-worker) was hot to analyze and write about back then ( http://cellperformance.beyond3d.com/articles/index.html ).

    As a hobbyist game developer, I'm curious - are these concerns just as valid today?

    And welcome aboard!

    @dkf said:

    Usually, the interaction with the CPU cache and memory fetch predictor matters more than anything else. Code that works well with those goes much faster than a simple count of cycles would lead you to expect. Measure, don't guess.

    And that's heavily dependent on the type of CPU, isn't it? Nowadays, there are so many unknowns; it's like tuning a poorly-performing SQL query.



  • @Groaner said:

    As a hobbyist game developer, I'm curious - are these concerns just as valid today?

    The PS3 was a complete mutant.



  • @Groaner said:

    As a hobbyist game developer, I'm curious - are these concerns just as valid today?

    IIRC, the XBone and PS4 are both running on bog-standard x86(-64?) architectures, as does the XB360, it was just the PS3 that was

    @blakeyrat said:

    a complete mutant.

    If those are your target platforms, code as if you were planning to run the game on one of those 'gaming laptop' things.



  • It took Bethesda like... 6 months to even get Gamebryo/Creation Engine running on the PS3 at all. Then another 6 months before they could figure out how to get it to run the base game and the DLCs. And Bethesda ain't rank amateurs.



  • Bethesda has yet to implement an interface where you can click on buttons without the wrong button being randomly selected.



  • Skyrim felt particularly bad for this, but Skyrim was clearly designed around being played on a controller. Earlier games didn't have that problem.



  • @trithne said:

    If those are your target platforms, code as if you were planning to run the game on one of those 'gaming laptop' things.

    My target platform is "beefy gaming desktops from about 4 years ago," which should be lenient enough.



  • @Groaner said:

    As a hobbyist game developer, I'm curious - are these concerns just as valid today?

    And welcome aboard!

    Heh, thanks; been a lurker for a while but figured it was time to finally pull the trigger on setting up an account. 😄

    It's been a while since I had to work at that low of a level on a CPU, since I'm mostly doing platform level of programming these days (i.e. ports, ports, and more ports), but generally-speaking, having some sense of what your compiler will with your code on your target platform is a decent mindset to have when doing game-programming and especially on consoles or console-like platforms (such as handhelds like the PSVita, where I am currently trying like hell to optimize a game that just doesn't want to be optimized.. sigh..).



  • The XBone and PS4 are bog-standard x86-64, as is the SteamBox as is everyone's Master Race gaming rig.

    The Wii-U is essentially a tri-core PowerMac G3, with only trivial other improvements from the Wii's and GameCube's single-core G3. (Pendant's corner: Yes, I know that Gekko/Broadway/Expresso aren't stock G3, and have Altivec and all kinds of G4- and G5-derived goodness, but fundamentally they're G3's and you know it.)

    The PS3 uses a special "Cell" processor with one "PPE" similar to a PowerMac G5, and eight (hardware) / seven (unlocked) / six (available to games) independent "SPE" specialized processors, with a strong focus on vector math and very little on I/O or management functions.

    The XBOX 360 has a tri-core Cell PPE, no SPEs, and additional pipelining "goo". During development, Windows 2000 on PowerMac G5's were used to emulate the system.



  • Bethseda probably isn't the best example. Yes they made several great games, but the games have never been renowned because of great programming. Just great concepts.



  • @TwelveBaud said:

    The XBOX 360 has a tri-core Cell PPE, no SPEs, and additional pipelining "goo". During development, Windows 2000 on PowerMac G5's were used to emulate the system.

    I think this is the single most weird thing I've ever read.



  • Whyssat?

    Same OS kernel, same CPU (except the PowerMacs had 2 CPUs, not 3 cores)-- what else would you use?



  • @blakeyrat said:

    Whyssat?

    Same OS kernel, same CPU (except the PowerMacs had 2 CPUs, not 3 cores)-- what else would you use?

    While PowerPC support existed in NT, it was, so far as I knew, dropped for 2000. I didn't even know it was possible to run 2000 on a PPC. Also, Windows on a Mac back in the first half of the aughts is an oddity unto itself. And Windows + Mac = Console...

    As to what else I would use? I have no idea. I wasn't questioning whether it made sense, just commenting on how passing strange an arrangement it was.


Log in to reply