pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: till toenges <tt@kyon.de>
To: Kris Jurka <books@ejurka.com>
Cc: Luis Vilar Flores <lflores@evolute.pt>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: bytea memory improvement
Date: Tue, 26 Sep 2006 15:07:12 +0200
Message-ID: <45192600.5050704@kyon.de> (raw)
In-Reply-To: <Pine.BSO.4.63.0609260131040.29854@leary2.csoft.net>
References: <44EB8C82.1000203@evolute.pt>
	<Pine.BSO.4.63.0609260131040.29854@leary2.csoft.net>

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.



view thread (12+ messages)  latest in thread

Message-ID: <45192600.5050704@kyon.de>
Permalink:  ../45192600.5050704@kyon.de/
Also on:    postgresql.org/message-id/45192600.5050704@kyon.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: tt@kyon.de, books@ejurka.com, lflores@evolute.pt
  Subject: Re: bytea memory improvement
  In-Reply-To: <45192600.5050704@kyon.de>
  References: <44EB8C82.1000203@evolute.pt> <Pine.BSO.4.63.0609260131040.29854@leary2.csoft.net> <45192600.5050704@kyon.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox