Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #80764

Re: "Nearly a quarter-century later, why is C++ still so popular?"

From Juha Nieminen <nospam@thanks.invalid>
Newsgroups comp.lang.c++
Subject Re: "Nearly a quarter-century later, why is C++ still so popular?"
Date 2021-08-01 08:28 +0000
Organization Aioe.org NNTP Server
Message-ID <se5lug$vfo$1@gioia.aioe.org> (permalink)
References (2 earlier) <sdr3p0$cvu$1@gioia.aioe.org> <sdrp6m$7bn$1@dont-email.me> <chine.bleu-DA14A8.07525728072021@reader.eternal-september.org> <sdtja3$17il$1@gioia.aioe.org> <0d40ea68-6b4f-4ac9-bdda-47f280aa3b84n@googlegroups.com>

Show all headers | View raw


?? Tiib <ootiib@hot.ee> wrote:
> On Thursday, 29 July 2021 at 09:54:13 UTC+3, Juha Nieminen wrote:
>> 
>> Of course, as it turns out, this paradigm is inefficient in modern CPUs 
>> (because of caches, pipelines, predictive branching, etc.) The CPU 
>> doesn't really like objects that are randomly placed in memory, thus 
>> with data being accessed from random memory locations. It also doesn't 
>> like branches it cannot predict. Or branching at all, especially 
>> indirect branching. (Also, compilers have a hard time optimizing 
>> code full of true function calls, because they can't see what the 
>> function is doing, and it hinders things like autovectorization.) 
> 
> When it matters to performance then there are presumably
> large containers of such objects? The boost::base_collection can help
> there as instead of allocating each object dynamically in random memory
> locations it keeps those in subcontainers by value. 

As mentioned earlier, that's a step in the right direction, but it doesn't
achieve optimal performance (with the possible exception of very small
objects whose every data member is accessed during the same iterative
process).

The reason why putting objects by value into arrays is better but not
optimal is because most often, for a given operation that you want
to perform on each object, you are only interested in one (or a few)
of their member variables. Quite often the objects will also contain
other members variables, which will cause the ones you are interested
in to be spaced out in the array, with big gaps.

So, even if you are traversing the array linearly from beginning to
end, you will be making jumps of the size of these gaps, which is
not optimal for cache locality. The number of cache misses will be
larger than if the data you are interested in was stored exclusively,
without any gaps.

This is one the unfortunate drawbacks of the otherwise brilliant idea
of modularity and object-oriented design: It groups related values into
the same class, which is nice designwise, but suboptimal for performance
because quite often you aren't handling *all* of these member values,
only certain ones, so you'll be jumping in larger steps than necessary.

Things like game engines and number-crunching applications want to
squeeze out every single clock cycle they can, so this design is not
good for them. They need a completely different approach from the
traditional class design.

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

"Nearly a quarter-century later, why is C++ still so popular?" Lynn McGuire <lynnmcguire5@gmail.com> - 2021-07-27 14:59 -0500
  Re: "Nearly a quarter-century later, why is C++ still so popular?" Siri Cruise <chine.bleu@yahoo.com> - 2021-07-27 13:48 -0700
    Re: "Nearly a quarter-century later, why is C++ still so popular?" Vir Campestris <vir.campestris@invalid.invalid> - 2021-07-27 22:05 +0100
      Re: "Nearly a quarter-century later, why is C++ still so popular?" Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-07-27 14:23 -0700
        Re: "Nearly a quarter-century later, why is C++ still so popular?" legalize+jeeves@mail.xmission.com (Richard) - 2021-08-05 19:49 +0000
          Re: "Nearly a quarter-century later, why is C++ still so popular?" Jorgen Grahn <grahn+nntp@snipabacken.se> - 2021-08-19 20:08 +0000
            Re: "Nearly a quarter-century later, why is C++ still so popular?" Siri Cruise <chine.bleu@yahoo.com> - 2021-08-19 18:20 -0700
              Re: "Nearly a quarter-century later, why is C++ still so popular?" Juha Nieminen <nospam@thanks.invalid> - 2021-08-20 06:13 +0000
              Re: "Nearly a quarter-century later, why is C++ still so popular?" Jorgen Grahn <grahn+nntp@snipabacken.se> - 2021-08-20 06:17 +0000
                Re: "Nearly a quarter-century later, why is C++ still so popular?" Siri Cruise <chine.bleu@yahoo.com> - 2021-08-20 00:03 -0700
                Re: "Nearly a quarter-century later, why is C++ still so popular?" Juha Nieminen <nospam@thanks.invalid> - 2021-08-20 11:03 +0000
                Re: "Nearly a quarter-century later, why is C++ still so popular?" mickspud@downthefarm.com - 2021-08-20 15:19 +0000
              Re: "Nearly a quarter-century later, why is C++ still so popular?" "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-08-20 14:26 +0200
                Re: "Nearly a quarter-century later, why is C++ still so popular?" Öö Tiib <ootiib@hot.ee> - 2021-08-29 23:40 -0700
    Re: "Nearly a quarter-century later, why is C++ still so popular?" Cholo Lennon <chololennon@hotmail.com> - 2021-07-27 21:01 -0300
    Re: "Nearly a quarter-century later, why is C++ still so popular?" Juha Nieminen <nospam@thanks.invalid> - 2021-07-28 08:16 +0000
      Re: "Nearly a quarter-century later, why is C++ still so popular?" "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-07-28 16:22 +0200
        Re: "Nearly a quarter-century later, why is C++ still so popular?" Siri Cruise <chine.bleu@yahoo.com> - 2021-07-28 07:53 -0700
          Re: "Nearly a quarter-century later, why is C++ still so popular?" "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-07-28 21:23 +0200
            Re: "Nearly a quarter-century later, why is C++ still so popular?" Siri Cruise <chine.bleu@yahoo.com> - 2021-07-28 14:16 -0700
          Re: "Nearly a quarter-century later, why is C++ still so popular?" Juha Nieminen <nospam@thanks.invalid> - 2021-07-29 06:53 +0000
            Re: "Nearly a quarter-century later, why is C++ still so popular?" Öö Tiib <ootiib@hot.ee> - 2021-07-29 09:31 -0700
              Re: "Nearly a quarter-century later, why is C++ still so popular?" MrSpud_71i5@slwgrcbmd1l7yi1.org - 2021-07-30 11:21 +0000
              Re: "Nearly a quarter-century later, why is C++ still so popular?" Juha Nieminen <nospam@thanks.invalid> - 2021-08-01 08:28 +0000
                Re: "Nearly a quarter-century later, why is C++ still so popular?" Öö Tiib <ootiib@hot.ee> - 2021-08-01 05:49 -0700
                Re: "Nearly a quarter-century later, why is C++ still so popular?" Juha Nieminen <nospam@thanks.invalid> - 2021-08-02 10:23 +0000
                Re: "Nearly a quarter-century later, why is C++ still so popular?" MrSpud_rLY23@_h_.co.uk - 2021-08-02 15:05 +0000
                Re: "Nearly a quarter-century later, why is C++ still so popular?" Öö Tiib <ootiib@hot.ee> - 2021-08-03 04:57 -0700
                Re: "Nearly a quarter-century later, why is C++ still so popular?" Juha Nieminen <nospam@thanks.invalid> - 2021-08-03 12:16 +0000
                Re: "Nearly a quarter-century later, why is C++ still so popular?" Öö Tiib <ootiib@hot.ee> - 2021-08-03 06:01 -0700
                Re: "Nearly a quarter-century later, why is C++ still so popular?" Ian Collins <ian-news@hotmail.com> - 2021-08-08 13:03 +1200
                Re: "Nearly a quarter-century later, why is C++ still so popular?" "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-08-07 22:43 -0700
            Re: "Nearly a quarter-century later, why is C++ still so popular?" Vir Campestris <vir.campestris@invalid.invalid> - 2021-08-01 21:40 +0100
          Re: "Nearly a quarter-century later, why is C++ still so popular?" Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-07-29 09:53 +0100
          Re: "Nearly a quarter-century later, why is C++ still so popular?" Manfred <noname@add.invalid> - 2021-07-30 13:51 +0200
      Re: "Nearly a quarter-century later, why is C++ still so popular?" Manfred <noname@add.invalid> - 2021-07-30 13:40 +0200
  Re: "Nearly a quarter-century later, why is C++ still so popular?" Bonita Montero <Bonita.Montero@gmail.com> - 2021-07-28 04:05 +0200
    Re: "Nearly a quarter-century later, why is C++ still so popular?" MrSpud_oyam9ltRb0@khlkg.info - 2021-07-28 09:30 +0000
  Re: "Nearly a quarter-century later, why is C++ still so popular?" Bo Persson <bo@bo-persson.se> - 2021-07-28 08:19 +0200
  Re: "Nearly a quarter-century later, why is C++ still so popular?" "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-08-03 13:10 -0700
    Re: "Nearly a quarter-century later, why is C++ still so popular?" Lynn McGuire <lynnmcguire5@gmail.com> - 2021-08-03 18:37 -0500
      Re: "Nearly a quarter-century later, why is C++ still so popular?" Cholo Lennon <chololennon@hotmail.com> - 2021-08-05 18:17 -0300
  Re:"Nearly a quarter-century later, why is C++ still so popular?" Blue Hat <blue_hat@hackershaven.com.jm> - 2021-08-08 13:33 -0500

csiph-web