News for hackers. Stuff that matters.
Re:Why git is so fast (or why Java is not as fast as C) by DarkShikari on Saturday January 02, 2010 @03:41AM (#1026974)
This has always been true and will continue to be true.

It's possible to build a high level language that's as fast as C? Sure--but only if you restrict the programmer to the same amount of effort in both languages. If your application is one where it's worthwhile applying a great deal of extra programmer time in order to improve performance, a low level language will always win because it exposes more of the native machine.

The goal of a high-performance high-level language should be to provide C-like performance for a reasonably unoptimized application. Once one starts to optimize a program down to the last instruction, staying on par with a low level language becomes simply impossible for a high level language.

In my experience, every level of abstraction one creates away from the machine limits your performance by some amount. This can be demonstrated without even leaving assembly language!

Fastest possible: raw assembly code in a NASM-like assembler. With this, you can write basically any code possible with no limitations, at the cost of extremely high programmer time costs.

Shortcut: Use inline assembler instead of NASM to simplify calling convention and other niceties.

Cost: There's now a whole bunch of stuff, like calling convention optimization and computed jumps, which you can no longer do.

Shortcut: Use compiler intrinsics instead of raw assembly.

Cost: You can no longer tweak your algorithm to minimize register spills because you aren't directly controlling spills anymore.

Shortcut: Use a set of macros (like my project does) for handling calling convention, MMX/SSE abstraction, and other such simplifications.

Cost: You tend to overlook optimizations that apply to one possible output of the abstraction and not others, resulting in either messes of ifdefs or suboptimal code--the former of which is of course violating the abstraction.

Shortcut: Use a framework like liboil to write SIMD assembly instead of native code.

Cost: By using generic SIMD operators, you lose access to specialized architecture-specific operations, along with the aforementioned issue of register spills.

Here we haven't even gotten beyond assembler and we're already losing performance. Now scale this up to C and beyond: abstraction inherently comes at a performance cost. It isn't even merely a function of language: abstractions within a language reduce performance as well.

Re:Why git is so fast (or why Java is not as fast as C) by barrkel on Saturday January 02, 2010 @05:24AM (#1027052)
Of course, managed languages can buy you other things, such as inlining indirect method calls by rewriting the call site (polymorphic inline caching), dynamic profile-guided optimization, not to mention the fact that garbage collection is often faster than manual deallocation, depending on the nature of the problem and the pattern of allocations. (Of course, design of managed applications can benefit greatly from awareness of how the GC works).

WRT SIMD operators, I'll point you to Mono.Simd.

Re:Why git is so fast (or why Java is not as fast as C) by blasdel on Saturday January 02, 2010 @06:13AM (#1027089)
I found that I had to read your comment carefully to realize that I agreed with you, because I'd already flipped the bozo bit 3 words in when you unnecessarily used parochial microsoft nomenclature.
Re:Why git is so fast (or why Java is not as fast as C) by barrkel on Saturday January 02, 2010 @06:27AM (#1027098)
What word would you recommend I use to cover everything from Ruby to Java?

FWIW, I think you'll make the same mistake pretty often if you continue to think of folks who play in the MS pond as bozos. There are reasons MS is a leader in many markets.

Re:Why git is so fast (or why Java is not as fast as C) by blasdel on Saturday January 02, 2010 @09:19AM (#1027220)
Anything but 'managed' -- while conceptually it covers things quite nicely, in practice it's used almost exclusively to mean "runs on the CLR", by those living solely within the Microsoft ecosystem whose knowledge of programming languages comes from Microsoft marketing materials. It's a loaded term.

There's plenty of nomenclature abuse in that ecosystem, like using 'assemblies' to refer to packages or 'blittable' for SHM.

'Garbage Collected' (or GCed) works fine instead of 'managed', especially since 'runs on a VM' is pretty nebulous, and the whole C++/CLI thing adds some confusion.

Re:Why git is so fast (or why Java is not as fast as C) by barrkel on Saturday January 02, 2010 @11:20AM (#1027327)
I don't use it to exclusively mean CLR-hosted, and to be frank, I think the meaning is pretty clear outside of MS contexts. I believe "GCed" focuses too much on the memory allocation strategy; which while important for many of the practical advantages of managed languages, I think it ends up lopsided.

Finally, more people using a word in an alternative way is the path to controlling its meaning, rather than avoiding the word altogether, cf "queer" and the like.

Re:Why git is so fast (or why Java is not as fast as C) by delackner on Saturday January 02, 2010 @11:11PM (#1028181)
What meaning does "managed" have to you? I wasn't aware of a generic meaning. A virtual-machine-based language that happens to include garbage collection?
Re:Why git is so fast (or why Java is not as fast as C) by barrkel on Sunday January 03, 2010 @04:41AM (#1028389)
Generally it means type-safe and memory-safe, at least by default; is not usually precompiled (in practice precompilation is avoided for linking flexibility); and has a runtime which is at least nominally independent of the programs that run on it, e.g. that would need separate installation if not packaged as part of a larger environment.

The combination of type and memory safety usually requires a garbage collector, though it's not strictly necessary.

Re:Why git is so fast (or why Java is not as fast as C) by sid0 on Sunday January 03, 2010 @01:31AM (#1028293)
> Anything but 'managed' -- while conceptually it covers things quite nicely, in practice it's used almost exclusively to mean "runs on the CLR"

Evidence? I know at least one Mozilla dev who calls JavaScript "managed". I call such languages "managed" too, and I write much more non-CLR code than CLR code.

Re:Why git is so fast (or why Java is not as fast as C) by Locke1689 on Saturday January 02, 2010 @03:47AM (#1026978)
Couldn't agree more. One thing to remember though: "Premature optimization is the root of all evil." C Git is optimized and fast. Mercurial, with a combination of Python and C, is almost as fast. Maybe not quite as fast, but fast enough for me. A lot of the time those optimizations just don't pay off in terms of programmer time.
Re:Why git is so fast (or why Java is not as fast as C) by DarkShikari on Saturday January 02, 2010 @03:54AM (#1026985)
Slightly tangential, but I think "Premature optimization is the root of all evil." is the most misquoted statement in the history of computer science. Most importantly, people tend to misinterpret "premature" to mean "any time before the software is done" or similar.

I can't even count the number of times where I've worked on or watched a project where performance is important and the following series of events occurs:

1. Module is designed with that quote in mind: it must be simple to implement and performance is unimportant. Note that this isn't a prototype: this is a plan for the actual final product.

2. Module is built and finished, then submitted for a review. The reviewers, knowing the importance of performance for this module, point out a number of ways that the module is extremely suboptimal.

3. Because of the assumptions so heavily ingrained into the module, implementing these performance improvements--which could have been foreseen as necessary far earlier--requires a near-complete rewrite of a large part of the module.

It's exactly as if we finished our software and our customer decided that his requirements were actually totally different--except in this situation, it's entirely our fault, because performance was a requirement and we ignored it because we didn't want to optimize "prematurely". If you want performance, you have to design with performance in mind; if you don't, and then decide later you want performance, the cost of your earlier decision is magnified a hundredfold.

I have almost never seen that quote used correctly.

Re:Why git is so fast (or why Java is not as fast as C) by barrkel on Saturday January 02, 2010 @05:08AM (#1027032)
Well, the fact that it says that something "premature" is causing a problem seems to me to mean that it's actually a tautology. It's like saying kids are immature; but of course, what is more of the nature of an immature person than a child?

So yes, optimizations that are made before they should have been made, should not be made. It tells us little about optimizations other than that there is a time for which they are premature, and doing them at that time is premature.

Re:Why git is so fast (or why Java is not as fast as C) by philh on Saturday January 02, 2010 @08:07AM (#1027162)
I think the important bit is "the root of all evil": it also tells us that doing optimisations prematurely has the potential to destroy your project. Compare with something like, "premature optimisation will take a little longer to perform, and perhaps be not quite as optimal, but isn't that big a deal in the long run, really."
Re:Why git is so fast (or why Java is not as fast as C) by JulianMorrison on Saturday January 02, 2010 @06:31AM (#1027101)
I always though that what that one quote meant was: measure, then optimize. It's no use tuning the hell out of a function that hardly features in your profiler results.
Re:Why git is so fast (or why Java is not as fast as C) by silentbicycle on Saturday January 02, 2010 @08:51AM (#1027193)
Agreed, though it would be clearer if the quote went, "Uninformed optimization..." or "Doing optimization without measuring first...".
Re:Why git is so fast (or why Java is not as fast as C) by xsmasher on Saturday January 02, 2010 @04:44PM (#1027708)
That, and also optimizing code that later gets thrown out entirely because requirements or other factors change. There's no benefit to optimizing code that goes in the bit bucket.
Re:Why git is so fast (or why Java is not as fast as C) by cschep on Saturday January 02, 2010 @05:11PM (#1027755)
Yes, or even just figure out HOW (you're going) to measure it.
Re:Why git is so fast (or why Java is not as fast as C) by Locke1689 on Saturday January 02, 2010 @01:09PM (#1027443)
You have a good point, but I don't think I asserted that any of those points are correct. I mostly agree with JulianMorrison on this one, although I think sometimes you can see performance bottlenecks coming. If you know an inner loop needs to be faster than your interpreted language can normally do, you might as well write that segment in C or ASM from the beginning. Mercurial still seems to me like a good example of optimization done correctly.
Re:Why git is so fast (or why Java is not as fast as C) by gruseom on Saturday January 02, 2010 @01:51PM (#1027494)
Wow, did you ever hit the nail on the head. I've been saying this for a long time (edit: e.g. http://news.ycombinator.com/item?id=96186, http://news.ycombinator.com/item?id=173949), wondering why I'd never run across anybody making what seems an obvious point. At last I have!

The important decisions around performance have to do with design, not optimization. Knuth's original principle was quite explicit: forget about most small efficiencies. But people commonly use it to justify not thinking about large ones. "Don't micro-optimize prematurely" somehow got changed into "don't think about performance until the end of the project".

Re:Why git is so fast (or why Java is not as fast as C) by billswift on Saturday January 02, 2010 @08:39AM (#1027178)
Maybe someone should come up with a clearer statement, "Don't optimize beyond need", for example. At least it's suggesting that there can be a need for optimization, and that too much optimization can be a problem.
Re:Why git is so fast (or why Java is not as fast as C) by SapphireSun on Saturday January 02, 2010 @01:50PM (#1027493)
There is an intermediate state where you make it "just work" but design it so that it's easy to speed up the algorithms later. Premature optimization makes you waste time on dumb stuff, but leaving yourself a way out is a lot less costly than optimizing everything and lets you avoid the problem you mentioned.
Re:Why git is so fast (or why Java is not as fast as C) by wglb on Saturday January 02, 2010 @10:04AM (#1027264)
That is why the rewording I use is "First make it right, then make it fast". If you make it fast first, then that is premature optomization.
Re:Why git is so fast (or why Java is not as fast as C) by ajross on Saturday January 02, 2010 @02:14PM (#1027524)
But that's just saying the same thing. The point being made above is that working "correctly" simply isn't enough if performance is a design goal too (or rather, correct operation requires that the software meet the performance goals at design time). So if you start out working on only half the problem, you'll still fail.
Re:Why git is so fast (or why Java is not as fast as C) by wglb on Sunday January 03, 2010 @03:43PM (#1029100)
My experience has shown me that it is very difficult to know where the performance bottlenecks are without measurement. You can't measure it if you haven't built it, and if it is not correct, why bother?

I have always taken this to mean what the original "premature optimization" quote is all about. I felt that making the statement a little simpler helps my focus.

Re:Why git is so fast (or why Java is not as fast as C) by rikthevik on Saturday January 02, 2010 @04:46AM (#1027021)
...Maybe not quite as fast, but fast enough for me...

Given how fast computers are these days, the powerful standard libraries high level languages give you and the fact that bugs per line is constant regardless of language - high level languages start to look pretty good. Programs don't need to be fast as possible, they just need to be fast enough.

Re:Why git is so fast (or why Java is not as fast as C) by ssp on Saturday January 02, 2010 @06:12AM (#1027088)
"Computers these days" have always been fast; if that were an argument for anything, performance would not matter at all anymore.

If computing power is fungible, then a 10% performance improvement translates into a 10% saving on the hardware budget. This matters for data centers, and it matters for embedded systems where using a slightly cheaper component in a million devices might mean saving a million dollars.

I think the fallacy of the fast, modern computer comes from the fact that PCs are not very fungible at all; they come in discrete performance steps. And since your application is pretty unlikely to be the most demanding one, it will probably run just fine even without much optimization.

Re:Why git is so fast (or why Java is not as fast as C) by igouy on Saturday January 02, 2010 @09:12AM (#1027213)
> the fact that bugs per line is constant regardless of language

"fact"?

More like an observation that must be re-tested and re-established with each change in tooling.

Is Java bugs per line the same for IntelliJ IDEA and Emacs?

(And of course let's remember - bugs per line when? During development? In product?)

Re:Why git is so fast (or why Java is not as fast as C) by steveklabnik on Saturday January 02, 2010 @11:58AM (#1027362)
That is what the study said. It holds constant across languages and tools.

Now, if I could find a link for you, that'd be awesome. My google-fu is weak today.

Re:Why git is so fast (or why Java is not as fast as C) by rdtsc on Saturday January 02, 2010 @05:05AM (#1027029)
Another thing to keep in mind before optimizing is the 80/20 rule. Usually only a small part of the program (20%) needs optimizing.

Of course one needs actual performance numbers (via profiling for example) before knowing what to optimize. There is nothing worse than faith-based performance assumptions. I have seen months being wasted re-writing code in a lower level language to "make things faster" only to find out that it didn't make a difference, the code was disk or network bound and not CPU bound.

Re:Why git is so fast (or why Java is not as fast as C) by vii on Saturday January 02, 2010 @08:42PM (#1028027)
This completely misses the point. The reason JGit cannot compete with Git is not that it is using an extra cycle or two to make function calls. The problem is that Java cripples you in the sort of data-representations you can use -- no mmap, no value types -- forcing lots of extra copying. There's no reason a language can't provide these features, and I don't know that they require significant extra programmer effort. C# does it, etc.