Performance of LargeObject.write() with PreparedStatement.setBlob()

From: "David Wall" <d(dot)wall(at)computer(dot)org>
To: "pgsql-jdbc" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Performance of LargeObject.write() with PreparedStatement.setBlob()
Date: 2002-09-02 17:09:58
Message-ID: 010a01c252a3$9151cfc0$3201a8c0@expertrade.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Another check of the code shows that the LargeObject.write(byte[]) is
efficient with buffers since the entire buffer is being written, whereas
write(byte[] buf,int off,int len) has to create a new buffer and then copies
the data in. This is probably okay since the assumption is that you
wouldn't use the latter if you wanted to write the entire buffer, and making
a check in each call to see if (off==0 && len=buf.length) to avoid the
buffer creation and copy may be overkill.

Instead, a change to PreparedStatement.setBlob() might be able to do this
with:

if ( numRead == buf.length )
los.write(buf);
else
los.write(buf,0,numRead);

This is in the loop where the blob is being written out in 4k buffers. Note
that the call is always a zero-based buffered, and all except the "last"
write of a blob would include a full buffer. This simple test would reduce
a 4k buffer being created and copied on each los.write call except for the
last one.

Thoughts?
David

Browse pgsql-jdbc by date

  From Date Subject
Next Message Thomas O'Dowd 2002-09-03 03:28:45 7.3 support?
Previous Message David Wall 2002-09-02 16:40:21 Re: setBlob loop performance?