Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id DD3409FB337 for ; Tue, 26 Sep 2006 10:12:36 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 63179-10 for ; Tue, 26 Sep 2006 13:12:32 +0000 (UTC) X-Greylist: delayed 00:05:00.517196 by SQLgrey- Received: from jcour.kyon.de (www.ky-on.de [213.9.98.91]) by postgresql.org (Postfix) with ESMTP id 94BDB9FB322 for ; Tue, 26 Sep 2006 10:12:32 -0300 (ADT) Received: from [10.0.4.2] (gw-cust1497.hkn.net [213.9.96.234]) (AUTH: LOGIN tt, SSL: TLSv1/SSLv3,256bits,AES256-SHA) by jcour.kyon.de with esmtp; Tue, 26 Sep 2006 15:07:29 +0200 id 0007DD8D.45192611.000143C3 Message-ID: <45192600.5050704@kyon.de> Date: Tue, 26 Sep 2006 15:07:12 +0200 From: till toenges User-Agent: Thunderbird 1.5.0.7 (Macintosh/20060909) MIME-Version: 1.0 To: Kris Jurka CC: Luis Vilar Flores , pgsql-jdbc@postgresql.org Subject: Re: bytea memory improvement References: <44EB8C82.1000203@evolute.pt> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.135 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200609/120 X-Sequence-Number: 15838 Kris Jurka wrote: > I'm not super impressed with these timing results. They are certainly > showing some effects due to GC, consider the rise in time here at 10.5MB. The method isn't neccessarily much faster, especially when there are only a few megabytes involved. This is very difficult to benchmark in the presence of a garbage collector. > I've committed this to CVS HEAD with a rather arbitrarily set > MAX_3_BUFF_SIZE value of 2MB. Note that this is also the escaped size, so > we may actually be dealing with output data a quarter of that size. If > anyone could do some more testing of what a good crossover point would be > that would be a good thing. AFAIK the MAX_3_BUFF_SIZE entry was a debug artifact. Not needed any more. The new method is always faster or at least as fast as the old method, because it requires fewer memory accesses. 3 Buffers: Buffer1 zeroing (vm intern) Buffer1 filling Buffer2 zeroing (vm intern) Buffer1 reading Buffer2 writing Buffer3 zeroing (vm intern) Buffer2 reading Buffer3 writing Total: 8 memory accesses. Eventually Buffer3 reading, but that's not part of the driver. 2 Buffers: Buffer1 zeroing (vm intern) Buffer1 filling Buffer1 reading (the new pass) Buffer2 zeroing (vm intern) Buffer1 reading Buffer2 writing Total: 6 memory accesses. Conclusion: The new method uses less memory. It must be faster as well, since everything else is fast in comparison to memory access. Additionally, it requires only 2 allocations, and memory allocation have some overhead as well, and mean more work for the garbage collector in the end. Even if the VM can do some magic to avoid zeroing the buffers, the newer method has one less memory access. It is always the winner.