LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-30-2009, 08:00 AM   #31
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197

Quote:
Originally Posted by jay73 View Post
source: IBM. If I have to choose between IBM and you, I won't have to think very long.
full article: http://www.ibm.com/developerworks/ja...-jtp09275.html
If I have to choose between years of experience plus a detailed understanding of the issues vs. a biased article doing obviously distorted comparisons, I won't have to think very long either.

Reread the article and give a little thought to the significance of the comparisons they do.
 
Old 01-30-2009, 09:11 AM   #32
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by jay73 View Post
And then again:
Quote:
Pop quiz: Which language boasts faster raw allocation performance, the Java language, or C/C++? The answer may surprise you -- allocation in modern JVMs is far faster than the best performing malloc implementations.
Ok, but is that because JVM allocates a generous amount of memory to itself, allowing it to allocate less space-efficiently, then spends its GC time piecing it back together? I'm sure malloc would work just as quickly if it was designed with the idea that it has as much as it wants to work with. And if JVM runs a more efficient algorithm, wouldn't that be +1 for the language JVM is written in? It isn't like "Java" makes the allocation; whatever logic it uses must inherently be written in a compiled language.
ta0kira
 
Old 01-30-2009, 10:14 AM   #33
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
You know there exists:
http://linux.maruhn.com/sec/libgc.html
 
Old 01-30-2009, 02:06 PM   #34
jay73
LQ Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 133Reputation: 133
Quote:
I'm sure malloc would work just as quickly if it was designed with the idea that it has as much as it wants to work with.
Yes, but the keyword here is if. And if the JVM had been implemented in hardware, we would be back to square one (there actuallly were experiments in this area in the mid-nineties, only the market was far too small back then too make it even remotely feasible).
The whole point is that many, many millions of research have gone into developing the best performing JVM; to do the same for a series of C/C++ projects would - in many cases and especially in larger projects - be absurdly expensive.

Quote:
You know there exists:
http://linux.maruhn.com/sec/libgc.html
Sure - and how much of a difference would that leave between C++ and java?

Last edited by jay73; 01-30-2009 at 02:10 PM.
 
Old 01-30-2009, 02:40 PM   #35
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by ta0kira View Post
I'm sure malloc would work just as quickly if it was designed with the idea that it has as much as it wants to work with.
You're too quick to accept the idea that malloc isn't already faster.

That article and the references it links to are heavily biased, primarily by selecting examples based on how badly they perform with malloc (but doing biased comparisons in a number of other ways as well).

A reasonable comparison must take into account the entire cost of the allocation / deallocation, which several of those comparisons don't and it should compare typical programs to similar programs, which none of those comparisons do.

There are some programs in which some versions of malloc do very badly. In my own experience, I've never worked on such a program for which simply switching to ptmalloc3 didn't fix the problem.
One of those references compared a C++ garbage collector that has many reasons (but no direct comparison) to be significantly slower than Java garbage collection vs. a few versions of malloc with a few programs selected for performing badly with those versions of malloc. The garbage collector did generally better than malloc, so you could expect a Java garbage collector to do even better. None of those versions of malloc were ptmalloc3.

I don't really understand the choice that was made to not make ptmalloc3 the default GNU malloc. I semi understand that in multi threaded applications doing malloc's from contending threads it will average slightly worse performance than the chosen default. But in non contending allocations (which are common even in a lot of multi threaded applications) it is slightly faster and it seems to be completely free of pathological cases (allocate/deallocate patterns that cause a major performance loss) while the default version has pathological cases.

In C++ on Linux (and somewhat on other platforms) you have the choice to substitute a different malloc or even something entirely different from malloc if you think your problem requires it.

But in typical application (not the ones chosen by those biased comparisons) any common version of malloc will perform better than any garbage collector.

You are correct that most memory allocation systems could benefit further from being more wasteful of virtual memory, assuming the waste of virtual memory itself has no cost. A garbage collector benefits more from that than a malloc or similar system. Malloc or similar systems typically don't waste a lot of virtual memory, so it is hard to say what makes a fair comparison if you assume wasting virtual memory is free then compare a GC version that does to a malloc version that doesn't. The more serious flaw is the whole assumption that wasting virtual memory is free.
 
Old 01-30-2009, 03:26 PM   #36
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by johnsfine View Post
The more serious flaw is the whole assumption that wasting virtual memory is free.
Yes, much in the same way that "we'll just throw more hardware at it" is used as a serious solution to algorithm inefficiency.
ta0kira
 
Old 01-30-2009, 03:33 PM   #37
ErV
Senior Member
 
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Blog Entries: 3

Rep: Reputation: 62
Quote:
Originally Posted by ta0kira View Post
Ok, but is that because JVM allocates a generous amount of memory to itself, allowing it to allocate less space-efficiently, then spends its GC time piecing it back together? I'm sure malloc would work just as quickly if it was designed with the idea that it has as much as it wants to work with. And if JVM runs a more efficient algorithm, wouldn't that be +1 for the language JVM is written in? It isn't like "Java" makes the allocation; whatever logic it uses must inherently be written in a compiled language.
ta0kira
I know that memory allocation can quickly become bottleneck if abused (experienced it). It isn't very fast for large blocks and certainly isn't instant. For example, in situation where you need to frequently allocate and then destroy blocks of data of larger but variable size, the best bet will be to allocate one block, reuse it and increase its' size when necessary. I also think that I saw recommendation to avoid allocating memory too often in game development. Also, AFAIK alloca is faster than malloc.

Quote:
Originally Posted by johnsfine View Post
But in typical application (not the ones chosen by those biased comparisons) any common version of malloc will perform better than any garbage collector.
Garbage collector doesn't do the same thing as malloc. It frees memory, not allocates it.

Last edited by ErV; 01-30-2009 at 03:37 PM.
 
Old 01-30-2009, 03:58 PM   #38
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by ErV View Post
Garbage collector doesn't do the same thing as malloc. It frees memory, not allocates it.
By "perform better" I meant overall. All the costs associated with allocating and freeing memory compared between the two very different approaches to the issue.

In such a discussion, "malloc" or "garbage collector" don't refer to those parts of allocating or freeing memory but to the whole system of allocating and freeing memory in a system based on those parts.
 
Old 01-30-2009, 05:04 PM   #39
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by ErV View Post
Also, AFAIK alloca is faster than malloc.
That's because it only involves decrementing the stack pointer, but if used with C++ (i.e. in-place new) you have to manually call the destructor before it goes out of scope.
ta0kira

Last edited by ta0kira; 01-30-2009 at 05:08 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java plugin installed correctly for Firefox but not able to view any java applet tvn Linux - Software 10 04-15-2010 02:13 AM
Ubuntu 7.10 64bit - how to set java path to/redirect java to libjvm.so ? Thane Ubuntu 1 03-25-2008 05:52 PM
LXer: Java news met with cautious optimism in free Java community LXer Syndicated Linux News 0 11-14-2006 10:21 PM
Firefox refuses to load Java jnlp files - plugin and java ok Melsync Linux - Software 1 06-25-2006 04:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration