The Artima Developer Community
Sponsored Link

Weblogs Forum
Optimization: Me versus Guy Steele

31 replies on 3 pages. Most recent reply: Nov 5, 2005 1:10 AM by Bob Dobalina

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 31 replies on 3 pages [ 1 2 3 | » ]
Christopher Diggins

Posts: 1215
Nickname: cdiggins
Registered: Feb, 2004

Optimization: Me versus Guy Steele (View in Weblogs)
Posted: Sep 29, 2005 6:05 AM
Reply to this message Reply
Summary
Guy says: "Essentially, programmers shouldn't have to worry too much about optimizing while they're writing programs. Instead, that optimization can be done by compilers, either ahead of time or on the fly.", but I disagree.
Advertisement
Guy Steele is a well respected language designer (designed Scheme, co-wrote the Java spec, etc.) and he has this to say about optimization:
"Essentially, programmers shouldn't have to worry too much about optimizing while they're writing programs. Instead, that optimization can be done by compilers, either ahead of time or on the fly."
I do agree the majority of programmers should not have to worry about optimization, but at the same time, other programmers, such as library designers, do need to worry about optimization. I believe that the principle responsibility for optimization should go to library writers. The limited scope of many languages, like Java, prevents this. Languages like C++ however enable library writers to push the envelope far further than what an optimizer can accomplish.

As way of a simple example, consider the ability in C++ to write a copy-on-write (COW) string class. Or a policy based string class. Or a small-string class. Or an immutable string class. A compiler can't read my requirements sheet, no matter how hard it tries.


Michael Feathers

Posts: 448
Nickname: mfeathers
Registered: Jul, 2003

Re: Optimization: Me versus Guy Steele Posted: Sep 29, 2005 6:40 AM
Reply to this message Reply
Here's a quote with more context:

"The mistake many language designers make is in failing to study history, failing to look at what worked and didn't work in the past, Steele says.

"For example, we're trying to use the dynamic compilation ideas from the Java HotSpot compiler to provide a productivity boost. Essentially, programmers shouldn't have to worry too much about optimizing while they're writing programs. Instead, that optimization can be done by compilers, either ahead of time or on the fly."

By measuring how the programming is behaving, he explains, information can then be fed back into a compiler so it can reorganize the program while it's running."

Guy is on target here. I'm eager to see how this works with scientific computation.

Keith Ray

Posts: 658
Nickname: keithray
Registered: May, 2003

Re: Optimization: Me versus Guy Steele Posted: Sep 29, 2005 7:31 AM
Reply to this message Reply
One of those "funny" things about C++ and its culture of "optimization" is that C++ tends to encourage the writing of inefficient code : copy-constructors and assignment-operators, which copy the contents of an object, whereas other languages where all objects are on the heap, only have to copy a pointer for assignment, parameter-passing or return from a function.

The std::string class ends up storing its string data on the heap anyway, but it has to implement reference-counting to avoid making unnecessary copies of strings (also expensive), and jumps through hoops to make THAT thread-safe: all extra work compared to languages that have garbage collection built-in and the option of 'immutable' string classes (you don't both copying immutable strings, in fact for Cocoa, the "copy" method of the immutable string class is no-op -- and you use a mutable string class when you need to).

You might think all "efficient" embedded software is written in C++ or C, but Smalltalk is used by many if not most chip fabricators, and many device manufacturers:

http://www.cincom.com/global/eng/profiles/adventacontroltechnologiesdetail.html

See also http://www.smalltalk.org/versions/OOVM.html

Christopher Diggins

Posts: 1215
Nickname: cdiggins
Registered: Feb, 2004

Re: Optimization: Me versus Guy Steele Posted: Sep 29, 2005 7:44 AM
Reply to this message Reply
> "The mistake many language designers make is in failing to
> study history, failing to look at what worked and didn't
> work in the past, Steele says.

To what do you think he is referring to here? Static optimization? Has it really failed? I see no evidence of that. What about template metaprogramming and other generative programming techniques? As far as I can tell they have been very successful: ATLAS (Automatically Tuned Linear Algebra Software), Lex, Flex, Yacc, and Bison, Blitz++, YARD (Yet Another Recursive Descent Parser), FFTW (Fastest Fourier Transform in the West) etc. History as I know it says very clearly, that generative programming hold an enormous amount of promise when performance is an issue.

History AFAIK has very little to say so far about dynamic profiling and rewriting, as it is a relatively immature technology. That fact that it has worked well for Java so far is completely inconsequential, because Java is inefficient to begin with.

> "For example, we're trying to use the dynamic compilation
> ideas from the Java HotSpot compiler to provide a
> productivity boost. Essentially, programmers shouldn't
> have to worry too much about optimizing while they're
> writing programs. Instead, that optimization can be done
> by compilers, either ahead of time or on the fly."
>
> By measuring how the programming is behaving, he explains,
> information can then be fed back into a compiler so it can
> reorganize the program while it's running."
> Guy is on target here.

The problem with this approach is that it doesn't factor in the cost of measurement and reorganization. An already optimized program will suffer greatly, because CPU cycles will get wasted on measurement and calculation. On the fly optimization would simply not work for finely tuned libraries.

Christopher Diggins

Posts: 1215
Nickname: cdiggins
Registered: Feb, 2004

Re: Optimization: Me versus Guy Steele Posted: Sep 29, 2005 7:48 AM
Reply to this message Reply
The links got screwed up somehow:

FFTW = http://www.fftw.org/
ATLAS = http://www.netlib.org/atlas/
Blitz++ = http://oonumerics.org/blitz/
YACC, etc = http://dinosaur.compilertools.net/
YARD = http://www.ootl.org/yard/

Kay Schluehr

Posts: 302
Nickname: schluehk
Registered: Jan, 2005

Re: Optimization: Me versus Guy Steele Posted: Sep 29, 2005 9:21 AM
Reply to this message Reply
> History AFAIK has very little to say so far about dynamic
> profiling and rewriting, as it is a relatively immature
> technology. That fact that it has worked well for Java so
> far is completely inconsequential, because Java is
> inefficient to begin with.

History tells first of all that optimizing code for making our compiler happy results in low level, incomprehensible and very brittle code. On the long run each optimization is a kind of premature optimization. That's how I understand Steeles intention. Better code analysis techniques and dynamic specialization are therefore very welcome. If you want back into the 80s with C+++... = Heron you may go for it. From Steele we might expect more innovative concepts rooted in the discussions we all made over the last 15 years.

Todd Blanchard

Posts: 316
Nickname: tblanchard
Registered: May, 2003

Re: Optimization: Me versus Guy Steele Posted: Sep 29, 2005 9:32 AM
Reply to this message Reply
I agree with Guy.

Write the clearest most obvious code you can. Then profile it. Observe that the slowdowns are caused by something completely unexpected. Fix that. Repeat.

Premature optimization is a waste of energy/resources/money. Its quite possible (likely even) that you're spending all this time on some elaborate COW strategy and it turns out that your program hardly ever writes.

Optimization is usually counterintuitive and micro-optimization seldom pays off in any measureable way.

Michael Feathers

Posts: 448
Nickname: mfeathers
Registered: Jul, 2003

Re: Optimization: Me versus Guy Steele Posted: Sep 29, 2005 10:57 AM
Reply to this message Reply
> History AFAIK has very little to say so far about dynamic
> profiling and rewriting, as it is a relatively immature
> technology. That fact that it has worked well for Java so
> far is completely inconsequential, because Java is
> inefficient to begin with.

Efficiency is relative. Nearly everything done in C++ is inefficient compared to hand-tuned assembly language, and think about the hit we take when we avoid extending the microcode for our chip sets. How do we survive?

Max Lybbert

Posts: 314
Nickname: mlybbert
Registered: Apr, 2005

Re: Optimization: Me versus Guy Steele Posted: Sep 29, 2005 3:10 PM
Reply to this message Reply
Many people are missing cdiggins' statement:

/*I do agree the majority of programmers should not have to worry about optimization,
*/

I agree with him here, and I think most of the posters do as well. The only place for disagreement is in the "but" part:

/* but at the same time, other programmers, such as library designers, do need to worry about optimization. I believe that the principle responsibility for optimization should go to library writers.
*/

And a library designer may not know how the library will be used. Unless the library will come with a disclaimer such as "gives a good answer 99% of the time" or "only leaks memory in function foo(), which is used internally by the library but I won't say where or when" or "this library is usually pretty fast, but once in a while it will exhibit O(x^x) behavior and crash your computer by draining so many cycles," the designer will probably want to pay close attention to correctness, resource management and performance.

Does Java really solve the problem so that even library writers don't have to worry? I'm not convinced that the HotSpot compiler's automated optimization can compete with optimized C++. I recognize HotSpot can determine which methods are actually taking a long time when called as a stack machine, and JIT those methods, but I'm not convinced that competes with optimized native code.

Kay Schluehr

Posts: 302
Nickname: schluehk
Registered: Jan, 2005

Re: Optimization: Me versus Guy Steele Posted: Sep 29, 2005 4:47 PM
Reply to this message Reply
> Does Java really solve the problem so that even library
> writers don't have to worry? I'm not convinced that the
> HotSpot compiler's automated optimization can compete with
> optimized C++. I recognize HotSpot can determine which
> methods are actually taking a long time when called as a
> stack machine, and JIT those methods, but I'm not
> convinced that competes with optimized native code.

HotSpot is a pointer not the end of the evloution of JIT compiling techniques which can indeed be faster than static compiled programs in certain situations when it comes to program specialization and caching of dynamically compiled variants of specialized functions.

A little theory:

http://compose.labri.fr/documentation/pe/pe_overview.php3


Here is a real world example of a specializer for Python:

http://psyco.sourceforge.net/introduction.html


Just slightly more information about Fortress that won't highlight details in this respect very much:

http://research.sun.com/sunlabsday/docs/Talks/Track1/1.02_steele.pdf

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Optimization: Me versus Guy Steele Posted: Sep 30, 2005 1:39 AM
Reply to this message Reply
> History AFAIK has very little to say so far about dynamic
> profiling and rewriting, as it is a relatively immature
> technology. That fact that it has worked well for Java so
> far is completely inconsequential, because Java is
> inefficient to begin with.

I resent that statement :0) - no but on a serious tip, what studies
or BenchMark programs do you have to merit this statement?

It was initially true, but to my understanding Java is catching
up with the likes of C++ in terms of speed, etc.

Which kind of prooves Guy's point. I don't think the fact that
it has worked for Java is inconsequential - this kind of prooves
his point doesn't it? I'm pretty sure when the first windows
versions were out they worried less about efficiency and
optimization and more on Usability - hence the *supposed*
improvements. Ever watch "Pirates of the Silicon Valley"?
I don't think its spot on but apparently the Apple OS's
were way better (I'm assuming in efficiency and optimization)
than the M$ versions. A quote from the guy playing Bill Gates:
"You don't get it Steve, that doesn't matter!"

Max Lybbert

Posts: 314
Nickname: mlybbert
Registered: Apr, 2005

Re: Optimization: Me versus Guy Steele Posted: Sep 30, 2005 9:24 AM
Reply to this message Reply
Thanks for the pointers. I've been curious about the technique, if a little skeptical.

Max Lybbert

Posts: 314
Nickname: mlybbert
Registered: Apr, 2005

Re: Optimization Posted: Sep 30, 2005 1:19 PM
Reply to this message Reply
After reading some of that material, I have to say that, much like optimizations that put microkernels on the same footing as monolithics -- until optimizing those monolithics with the same techniques, nothing I've seen relies on an interpreted language.

Yes, the HotSpot compiler does look at code at runtime, and yes it does optimize at runtime, and yes that requires something of an interpreter -- but the actual optimization could be applied at compile time if the compiler knew it was useful.

In fact, many programmers have been doing this by hand for years. The book "the Pragmatic Programmer" suggests this exact kind of optimization based on profiling and use patterns.

damien morton

Posts: 15
Nickname: dmost
Registered: Jan, 2004

Re: Optimization: Me versus Guy Steele Posted: Sep 30, 2005 1:28 PM
Reply to this message Reply
The rubber meets the road when writing big complicated gui applications. In these applications, after noticing that the app actually works, the user notices whether it is fast.

So far, the world in general has declined to use big complicated gui applications written in java, because of their excessive use of memory and poor cpu performance.

So, it really depends on what you are doing, and what kind of programmers you are expecting to use your language.

Many programmers are simply incapable of optimising their code, and for them the automated approach is best. On the other hand, there is a whole class of applications you simply wouldnt ask them to write (or rather shouldnt).

On the other hand, where speed matters, you need a language that enables optimisation both of memory usage and performance.

Java is not that language. C and C++ are.

Jim Shi

Posts: 7
Nickname: jim2000
Registered: May, 2005

Re: Optimization: Me versus Guy Steele Posted: Oct 1, 2005 8:55 AM
Reply to this message Reply
> The rubber meets the road when writing big complicated gui
> applications. In these applications, after noticing that
> the app actually works, the user notices whether it is
> fast.
>
> Java is not that language. C and C++ are.

Some still believe the earth is flat, while most of us move on.

Flat View: This topic has 31 replies on 3 pages [ 1  2  3 | » ]
Topic: The Trouble with Searching for Open-Source Code Previous Topic   Next Topic Topic: Generics: Bounds Puzzle

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use