From owner-freebsd-current Wed Mar 13 22: 4:38 2002 Delivered-To: freebsd-current@freebsd.org Received: from critter.freebsd.dk (critter.freebsd.dk [212.242.86.163]) by hub.freebsd.org (Postfix) with ESMTP id 9C46937B405 for ; Wed, 13 Mar 2002 22:04:34 -0800 (PST) Received: from critter.freebsd.dk (localhost [127.0.0.1]) by critter.freebsd.dk (8.12.2/8.12.2) with ESMTP id g2E646np040629; Thu, 14 Mar 2002 07:04:08 +0100 (CET) (envelope-from phk@critter.freebsd.dk) To: John Indra Cc: freebsd-current@FreeBSD.ORG Subject: Re: malloc() and the stock Perl in -CURRENT (and -STABLE) In-Reply-To: Your message of "Thu, 14 Mar 2002 10:45:25 +0700." <20020314104525.B8244@office.naver.co.id> Date: Thu, 14 Mar 2002 07:04:06 +0100 Message-ID: <40628.1016085846@critter.freebsd.dk> From: Poul-Henning Kamp Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG In message <20020314104525.B8244@office.naver.co.id>, John Indra writes: >Dear all... > >This morning I found a very interesting mail. All of you can see it from: > >http://docs.freebsd.org/cgi/getmsg.cgi?fetch=1669241+0+current/freebsd-questions > >As stated in the mail, a simple Perl script like this: > >-- Begin -- > >#!/usr/bin/perl > >$temp = ""; >$begin = time; >for ($i = 0; $i < 1000000; $i++) { > $result .= "$i\n"; >} >print "Exec time: ", time - $begin, " secs\n"; > >-- End -- > >can show that there PROBABLY is something wrong with malloc() in -CURRENT >and -STABLE. No, there is nothing wrong as such, it is a deliberate design-choice in phkmalloc() which conflicts with perls use of realloc(). Basically I profiled a lot of programs and found that very few programs used realloc() and decided that consequently it was the least important of the entries from a performance point of view. The above perl program results in a loop more or less like: n = 2 for (i = 0; i < 1000000; i++) realloc(n++); Now, if you read _any_ malloc(3) man page, they will tell you that there is no way it can be guaranteed that this does not result in a lot of copying. (insert bikeshed discussion about wisdom of the above code, assume I maintain the opinion throughout that it is braindamaged to be that stupid in a so central program as perl) At the cost of considerable complexity (a mremap(2) implementation amongst other things), realloc in phkmalloc(3) can be optimised but it is not on my plate right now. -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message