Performance of LargeObject.write() with PreparedStatement.setBlob() - Mailing list pgsql-jdbc

From David Wall
Subject Performance of LargeObject.write() with PreparedStatement.setBlob()
Date
Msg-id 010a01c252a3$9151cfc0$3201a8c0@expertrade.com
Whole thread Raw
List 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


pgsql-jdbc by date:

Previous
From: "David Wall"
Date:
Subject: Re: setBlob loop performance?
Next
From: Thomas O'Dowd
Date:
Subject: 7.3 support?