Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Perl, Java, and malloc

by cyocum (Curate)
on Oct 09, 2005 at 13:41 UTC ( [id://498560]=perlquestion: print w/replies, xml ) Need Help??

cyocum has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Fellow Monks

I was reading an article, which was linked from Slashdot. It is about the oft repeated myth of the slowness of memory allocation and deallocation in the JVM.

What really caught my eye was this statement by the author of the article: "And allocation performance is not a trivial component of overall performance -- benchmarks show that many real-world C and C++ programs, such as Perl and Ghostscript, spend 20 to 30 percent of their total execution time in malloc and free -- far more than the allocation and garbage collection overhead of a healthy Java application"

Now the author links to a research article on the subject here (warning: it is a PDF file). A quick browse through the article shows that it was done using Perl 4.10: "Perl C Perl 4.10, is a publicly available report extraction and printing language commonly used on UNIX systems. The input script formatted the words in a dictionary into filled paragraphs."

Now, as far as I understand the situation, Java and Perl share the same idea of VM and Garbage Collection. So, I guess my question is: is this still true using the newest versions of Perl and if it is, what differences in the implementation of Perl make it so much slower than Java at allocating memory (the author claims 10 machine instructions while malloc is 60-100)?

Replies are listed 'Best First'.
Re: Perl, Java, and malloc
by pg (Canon) on Oct 09, 2005 at 16:56 UTC

    If anyone thinks that the author was interested in comparing Java and Perl's garbage collection, that was a misunderstanding.

    The author's real interest was to compare the memory management implementation between Java and traditional c/c++. Perl was merely mentioned as an example of large c programs.

    Whether the quoted source was based on Perl 4.10 or Perl 5.8 was not related to the interest of the author, and does not make a difference to the point the author was trying to make (all he cares is to pick some large c program, although 5.8 is totally different from 4.10 to Perl users, but that's irrelevant in that context). That was why an article in 1994 can still be quoted as a meaningful reference.

      I seem to have misapprehended the author's intent in my zealousness. I apologize. Next time, I should take a step back before posting. Thank you for pointing this out.

Re: Perl, Java, and malloc
by Zaxo (Archbishop) on Oct 09, 2005 at 13:55 UTC

    It's unsurprising that Perl 4.10 was used - the research article is dated 1994. Perl's changed a lot since then.

    Historically, Perl has used immediate reference-counted garbage collection, while Java used some sort of mark-and-sweep.

    After Compline,
    Zaxo

Re: Perl, Java, and malloc
by dave_the_m (Monsignor) on Oct 09, 2005 at 14:26 UTC
    The last time I profiled some perl code (2 years ago), malloc and free occupied about 1%. Of course, since Perl's reference-counting is built into the system everywhere, its hard to profile how much time is spent in reference counting.

    Dave.

Re: Perl, Java, and malloc
by Anonymous Monk on Oct 10, 2005 at 00:05 UTC

    Don't understand why Perl guys always feel that they are under attack?

      Well I think that is called vigilance so that Perl remains in shape and even better than others in the market.
        Indeed! And we don't become tapped when attacking...

      Probably has something to do with guys like you, sniping at us... But if that's what floats your boat, then go for it, tovarishch...

      A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://498560]
Approved by castaway
Front-paged by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2024-04-23 16:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found