FirebirdSQL / jaybird

JDBC driver for Firebird

Home Page:https://www.firebirdsql.org/en/jdbc-driver/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add methods for writing blob content directly from an array

mrotteveel opened this issue · comments

Similar to #766, performance of writes of blob content could be improved (especially for the pure Java implementation) by writing the segments directly from the array to the network stream (or the buffer used by JNA), skipping intermediate buffers. This would especially be worth it for byte arrays larger than the blobBufferSize, because right now large byte arrays will be copied over in blobBufferSize lengths, and writes with different offset or length not equal to the array size will be copied too as (max) blobBufferSize lengths, while writing from the source array directly into the network stream would allow us to write with the maximum segment size.

This will probably even be beneficial for writes larger than 50% of the blob buffer size under the assumption that multiple writes with that size will happen right after each other, because in the existing implementation, two writes of 50% + 1 will

  1. First write with size > blobBufferSize / 2 and size < blobBufferSize will copy into the buffer of the blob output stream
  2. Second write with size > blobBufferSize / 2 and size < blobBufferSize will flush that buffer, and then write itself (possibly with additional copying)

If the first write had directly gone to the network stream, we could have skipped the overhead of copying to the buffer (and then from the buffer to the network).

We might also be able to coalesce the buffer flush and a subsequent write into a single segment, but that might raise the complexity too much.

Also removed the limitation that FbBlob.putSegment throws an exception if the byte array is longer than the maximum segment size. Instead, it will now perform multiple roundtrips. The documentation of this method was contradictory on the behaviour (saying both that the implementation should batch longer arrays, but also that it should throw an exception for longer arrays; the actual implementations did the latter).