Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: brianh@bit3.com
Subject: Re: Final kick at the "Merced Guessing Game"
Date: 1997/10/01	[thread overview]
Message-ID: <EHDwD4.F7w@bit3.com> (raw)
In-Reply-To: 34326556.2216DC70@virginia.edu


In article <34326556.2216DC70@virginia.edu>,
Michael D. Nahas <nahas@virginia.edu> wrote:
>I'm afraid that I must admit that Maclaren, even with his outrageous
>claim, is correct.   Malde has missed the problem - it is not branching,
>but indirection, A.K.A. pointer chasing.
>
>For a standard function, you just branch to the address.  With C++'s
>virtual
>functions you either follow a pointer or perform an indexed lookup to a
>jump
>table, which will load the address you will jump to, and then branch to
>that
>address.
>
>Why is indirection bad?  When the destination address of a jump is known,
>the processor
>can begin fetching from the new address and continue executing.  When the
>destination address of the jump is unknown, the processor usually stalls
>until
>the address comes in from memory.   Some processors do have hardware to
>speed up indirect jumps, but the hardware was developed using C benchmarks,
>
>where 90% of indirect jumps are just returns from functions.

The problem is not the double indirection- which can be handled if the CPU 
prefetchs data as well as instructions- but the fact that you are doing two 
memory accesses now instead of one, and usually widely seperate memory
accesses (most implementations don't AFAIK actually keep the virtual 
function tables with the class data, but in a seperate structure shared by
all objects of the same type- which is usually somewhere far away from
where the data ends up).  This is a symptom of the fact that memory has not
increased in speed the same way CPUs have (I put 70ns memory into my 386-
granted, no FPM or EDO, but still... And the 386 still needed cache).

The only thing more painfull on performance than leaving cache and waiting on
main memory is leaving main memory and swapping pages into disk.  Compilers
(and programmers!) should worry more about locality of reference.

If you are going to blow cache, the question arises "is it worth it?".  For
sparse matricies, the answer is obviously yes (the alternative is to swap
like mad)- although the matrix solving programs should be written to be
cache aware, and keep locality of reference up.  For virtual functions,
I think the benefits outweigh the gains, although it depends critically on
what you're doing.  I note the Fortran is still one of the two best languages
for doing numeric computation in- only recently have there been C compilers
as good as Fortran compilers (and even in these cases you often find they
share an optimizer with a Fortran compiler- examples include SGI's MipsPro
compilers, and HP's compilers).

>
>The truely evil part of indirection is not in function calls, but in the
>non-array
>data structures of most programs.  Think of traversing a linked list.  To
>load the
>first node in the list, it takes as much time as the memory latency.  To
>load the
>second node, you must first load the first node, and then pay the cost of
>the
>memory latency time again.  So to traverse a N node linked list, it takes N
>times
>the memory latency.
>
>For most cases, the nodes are contiguous in memory and most programs run
>inside the L1 and L2 cache, so these latencies are not too bad for most
>programs.
>However, programs which do not fit in large L2 caches, such as sparse
>matrix
>programs and the X Windows system, pay heavily.  The latency time of going
>to
>main memory is growing exponentially in terms of CPU cycles.
>
>So, is this a problem, and if so, how do we fix it.  Yes, it is a problem,
>because any
>stall to the pipeline which prevents speculative execution is bad.  How do
>we
>solve it?  The first thing to do is to make programs which have this
>problem part
>of the SPEC Benchmarks.  This will make it the focus of everyone's
>attention.
>The other thing that can be done is to look at Compiler optimizations -
>many of
>the indirect function calls can be eliminated, especially if all the source
>is compiled
>together.  Separate compilation of object files requires general interfaces
>which
>prevent many optimizations.
>
>Also, a note on Java.  All Java functions are virtual and all require a
>general
>interface on a class level.  Lastly, all objects are referenced indirectly,
>so even an
>array of Java objects is two levels of indirection to get the object you
>want!  So,
>Java is even worse than C++.
>
>    Mike
>
>As always, comments and criticism welcome.
>
>--
>/********************************************************\
>*  Michael David Nahas           nahas@virginia.edu      *
>*  Graduate Student in CS        University of Virginia  *
>\********************************************************/
>

I don't speak for Bit 3.
Brian


-- 
"NT and security should never be used in the same breath."
                   - Winn Schwartau, EETimes #972, 22 September 1997 pp.96

                                                         -Brian



  parent reply	other threads:[~1997-10-01  4:00 UTC|newest]

Thread overview: 196+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-09-30  4:00 Final kick at the "Merced Guessing Game" Paul DeMone
1997-09-30  4:00 ` Guy Harris
1997-10-01  4:00   ` Tom Thornhill
1997-10-01  4:00 ` Richard A. Schumacher
1997-10-01  4:00 ` Tom Thornhill
1997-10-01  4:00   ` Paul DeMone
1997-10-01  4:00   ` Jim Hull
1997-10-01  4:00 ` Nick Maclaren
1997-10-01  4:00   ` Paul DeMone
1997-10-01  4:00   ` J. Corbally
1997-10-01  4:00     ` Nick Maclaren
1997-10-01  4:00       ` Ketil Z Malde
1997-10-01  4:00         ` Michael D. Nahas
1997-10-01  4:00           ` Stefan Monnier
1997-10-01  4:00             ` Nick Maclaren
1997-10-01  4:00               ` P Murray
1997-10-01  4:00                 ` Nick Maclaren
1997-10-02  4:00                   ` Vesa Karvonen
1997-10-02  4:00                     ` Joseph H Allen
1997-10-02  4:00                       ` Wilco Dijkstra
1997-10-03  4:00                         ` Stefan Monnier
1997-10-03  4:00                         ` Jason.Ozolins
1997-10-03  4:00                           ` Alex Colvin
1997-10-06  4:00                             ` Richard A. O'Keefe
1997-10-08  4:00                               ` Zalman Stern
1997-10-03  4:00                       ` Stefan Monnier
1997-10-02  4:00                   ` Andrew Glew
1997-10-02  4:00                 ` Torben AEgidius Mogensen
1997-10-02  4:00                   ` Patrick F. McGehearty
1997-10-02  4:00                     ` brianh
1997-10-03  4:00                     ` Virtual functions (was Re: Final kick at the "Merced Guessing Game") Steven Correll
1997-10-03  4:00                     ` Final kick at the "Merced Guessing Game" Michael Williams
1997-10-01  4:00               ` John Wilson
1997-10-01  4:00               ` Allen Kim
1997-10-02  4:00               ` Stefan Monnier
1997-10-03  4:00                 ` Richard A. O'Keefe
1997-10-02  4:00               ` Jon Leech
1997-10-03  4:00               ` Mike Smith
1997-10-03  4:00                 ` Nick Maclaren
1997-10-03  4:00                   ` Rob Barris
1997-10-03  4:00                     ` Andrew Glew
1997-10-05  4:00                       ` Gianni Mariani
1997-10-04  4:00                     ` Nick Maclaren
1997-10-04  4:00                       ` H. Eckert
1997-10-05  4:00                       ` Andy "Krazy" Glew
1997-10-06  4:00                         ` Nick Maclaren
1997-10-01  4:00           ` brianh [this message]
1997-10-02  4:00           ` Eric Hildum
  -- strict thread matches above, loose matches on Subject: below --
1997-10-02  4:00 Robert Harley
1997-10-02  4:00 ` Nick Maclaren
1997-10-02  4:00   ` Stanley Chow
1997-10-02  4:00 Robert Harley
1997-10-02  4:00 ` Nick Maclaren
1997-10-03  4:00 ` Richard A. O'Keefe
1997-10-03  4:00 Robert Harley
1997-10-06  4:00 ` Richard A. O'Keefe
1997-10-06  4:00   ` boo
1997-10-07  4:00     ` Richard A. O'Keefe
1997-10-06  4:00       ` Graham Hughes
1997-10-07  4:00       ` boo
1997-10-07  4:00         ` William Clodius
1997-10-07  4:00       ` William Clodius
1997-10-08  4:00         ` Richard A. O'Keefe
1997-10-08  4:00           ` William Clodius
1997-10-08  4:00           ` William Clodius
     [not found]         ` <y4wwjon203.fsf@mailhost.neuroinformatik.ruhr-uni-bochum.de>
1997-10-08  4:00           ` William Clodius
1997-10-08  4:00             ` Stanley Chow
1997-10-09  4:00         ` William Clodius
1997-10-10  4:00           ` Larry Kilgallen
1997-10-10  4:00             ` Zalman Stern
1997-10-11  4:00             ` Andrew Cruickshank
1997-10-12  4:00               ` Paul D. DeRocco
1997-10-13  4:00               ` Michael Williams
1997-10-08  4:00       ` Gregg E Economou
1997-10-08  4:00         ` Richard A. O'Keefe
1997-10-08  4:00         ` David Chase
1997-10-07  4:00     ` Serge Pachkovsky
1997-10-07  4:00       ` Martin Rodgers
1997-10-07  4:00         ` Greg Weeks
1997-10-07  4:00           ` Martin Rodgers
     [not found]           ` <343AAE5A.A3FCC9D@no.informatik.spam.tu-muenchen.thanks.de>
1997-10-09  4:00             ` Torben AEgidius Mogensen
     [not found]               ` <EHsr7B.Dt8@bit3.com>
1997-10-10  4:00                 ` Torben AEgidius Mogensen
     [not found]       ` <61cv5e$qn$6@vixen.cso.uiuc.edu>
1997-10-08  4:00         ` William Clodius
1997-10-07  4:00     ` Carlie Coats
1997-10-07  4:00       ` Paul Hsieh
1997-10-07  4:00         ` boo
1997-10-08  4:00           ` Carlie Coats
1997-10-08  4:00     ` James C. Stutts
1997-10-07  4:00 Robert Harley
1997-10-07  4:00 ` Shankar Unni
1997-10-08  4:00   ` boo
1997-10-09  4:00     ` Patrick F. McGehearty
1997-10-10  4:00       ` Richard A. O'Keefe
1997-10-15  4:00         ` David Chase
1997-10-16  4:00           ` William Clodius
1997-10-07  4:00 ` Nick Maclaren
1997-10-07  4:00 ` Martin Rodgers
1997-10-08  4:00 Robert Harley
     [not found] ` <343C0387.41C6@lanl.gov>
1997-10-08  4:00   ` boo
1997-10-09  4:00     ` Patrick Chase
1997-10-10  4:00       ` boo
1997-10-09  4:00     ` David Chase
1997-10-08  4:00       ` boo
1997-10-09  4:00       ` William Clodius
1997-10-09  4:00 ` David Chase
1997-10-08  4:00 Robert Harley
1997-10-08  4:00 ` William Clodius
1997-10-08  4:00 ` David Chase
1997-10-08  4:00 ` brianh
1997-10-08  4:00   ` boo
1997-10-09  4:00     ` Eric Hildum
1997-10-09  4:00     ` brianh
1997-10-11  4:00     ` Jan Vorbrueggen
1997-10-12  4:00       ` boo
1997-10-13  4:00         ` Carl Perkins
1997-10-13  4:00         ` Michael Williams
1997-10-13  4:00           ` Craig Burley
1997-10-13  4:00             ` Paul Rubin
1997-10-13  4:00               ` Craig Burley
1997-10-13  4:00               ` William Clodius
1997-10-14  4:00               ` Richard A. O'Keefe
1997-10-14  4:00                 ` Michael Williams
1997-10-14  4:00                   ` Richard Black
1997-10-15  4:00                     ` Michael Williams
1997-10-15  4:00                       ` Dr. Richard Black
1997-10-16  4:00                         ` Richard A. O'Keefe
1997-10-15  4:00                     ` Craig Burley
1997-10-18  4:00                     ` Bruce Hoult
1997-10-14  4:00                 ` Shankar Unni
1997-10-15  4:00                   ` Achim Gratz
1997-10-15  4:00                   ` Richard A. O'Keefe
1997-10-15  4:00                     ` Paul D. DeRocco
1997-10-15  4:00                       ` William Clodius
1997-10-15  4:00                       ` Joe Buck
1997-10-16  4:00                       ` Richard A. O'Keefe
1997-10-16  4:00                         ` Craig Burley
1997-10-17  4:00                     ` Shankar Unni
1997-10-15  4:00                 ` Paul Hsieh
1997-10-13  4:00             ` boo
1997-10-15  4:00               ` Craig Burley
     [not found]                 ` <623ek6$ef5$1@news.iastate.edu>
1997-10-16  4:00                   ` Craig Burley
1997-10-16  4:00                     ` SimGraphics
1997-10-17  4:00                       ` Craig Burley
1997-10-17  4:00                         ` William Clodius
1997-10-19  4:00                           ` Craig Burley
1997-10-17  4:00                         ` David Chase
1997-10-18  4:00                           ` Victor Yodaiken
1997-10-20  4:00                             ` Eric Hildum
1997-10-18  4:00                         ` Peter L. Montgomery
1997-10-19  4:00                           ` Craig Burley
     [not found]                             ` <3456700e.14141203@news.demon.co.uk>
1997-10-28  5:00                               ` Dirk van der Knijff
1997-10-20  4:00                           ` Richard A. O'Keefe
1997-10-20  4:00                             ` Peter L. Montgomery
1997-10-09  4:00   ` Gregg E Economou
1997-10-10  4:00     ` Jan Vorbrueggen
     [not found] ` <61ho3v$3m0$1@goanna.cs.rmit.edu.au>
1997-10-09  4:00   ` boo
1997-10-09  4:00     ` William Clodius
1997-10-10  4:00     ` boo
1997-10-11  4:00       ` Paul DeMone
1997-10-11  4:00       ` Toon Moene
1997-10-11  4:00       ` Patricia Shanahan
1997-10-13  4:00         ` Gregg E Economou
1997-10-13  4:00           ` Patricia Shanahan
1997-10-14  4:00           ` Richard A. O'Keefe
1997-10-15  4:00             ` boo
1997-10-16  4:00               ` Toon Moene
1997-10-16  4:00               ` Timothy A. Seufert
1997-10-16  4:00                 ` boo
1997-10-17  4:00               ` Richard A. O'Keefe
1997-10-20  4:00               ` Jason.Ozolins
1997-10-10  4:00     ` Tyson Richard DOWD
1997-10-12  4:00       ` boo
1997-10-13  4:00         ` Steve Tate
1997-10-13  4:00           ` boo
1997-10-13  4:00             ` Aaron Spink
1997-10-14  4:00               ` boo
1997-10-18  4:00                 ` tgg
1997-10-13  4:00           ` Bernd Paysan
1997-10-13  4:00           ` boo
1997-10-13  4:00             ` Victor Yodaiken
1997-10-14  4:00             ` Aaron Spink
1997-10-14  4:00             ` Jason.Ozolins
1997-10-15  4:00               ` boo
1997-10-15  4:00             ` David Chase
1997-10-13  4:00         ` Patricia Shanahan
1997-10-15  4:00           ` boo
1997-10-15  4:00             ` Patricia Shanahan
1997-10-10  4:00     ` Richard A. O'Keefe
     [not found]   ` <EHrwv9.2w3@world.std.com>
1997-10-10  4:00     ` David Gould
1997-10-10  4:00       ` Maynard Handley
1997-10-10  4:00     ` David Gould
1997-10-16  4:00       ` Patricia Shanahan
1997-10-08  4:00 Robert Harley
1997-10-08  4:00 ` Michael Meissner
1997-10-09  4:00 ` Richard A. O'Keefe
1997-10-09  4:00 Robert Harley
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox