Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: improve performance of PreparedStatement.setBlob, BlobInputStream, and BlobOutputStream with dynamic buffer sizing #3044

Merged
merged 13 commits into from
Dec 4, 2023

Commits on Dec 4, 2023

  1. Configuration menu
    Copy the full SHA
    7ee6a37 View commit details
    Browse the repository at this point in the history
  2. chore: add src/testFixtures to share test-related code across subproj…

    …ects
    
    Previously TestUtil.java was declared in src/test/..., and there was no way
    to reuse it in the benchmarks.
    vlsi committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    b4b28bf View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    3dea857 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    306e03e View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    d248442 View commit details
    Browse the repository at this point in the history
  6. perf: improve performance of BlobInputStream.read(b, off, len) with b…

    …uffering reads
    
    This reverts commit 3af3b32.
    
    Co-authored-by: Dave Cramer <davecramer@gmail.com>
    Co-authored-by: Brett Okken <brett.okken.os@gmail.com>
    
    There are several fixes on top of 3af3b32:
    
    1) The buffer is created lazily, and it is created only in case the number of requested bytes
    is less than the buffer size
    2) "small" read(byte[], int, int) can be buffered as well (e.g. if the buffer size exceeds the requested len)
    3) Added locks to read calls for consistency with the locking in mark/reset
    4) read(byte[], int, int) should return 0 when len=0
    5) refilling the bufer should read "bufferSize" amount rather than "the remaining length"
    vlsi committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    ac57b52 View commit details
    Browse the repository at this point in the history
  7. perf: add buffer scaling to BlobInputStream

    We start with 65K buffer, and increase it as the user requests more reads.
    It reaches reasonable performance for "full stream readouts", and it avoids
    loading large amount of data when the user needs first bytes only.
    vlsi committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    46aee2c View commit details
    Browse the repository at this point in the history
  8. feat: add LargeObject.write(ByteStreamWriter) so multiple buffers can…

    … be written at once without copying
    vlsi committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    b419750 View commit details
    Browse the repository at this point in the history
  9. perf: reduce array allocation in ByteStreamWriter.writeTo(ByteStreamT…

    …arget)
    
    Previously, the implementation always created a Channel with Channels.newChannel(outputStream),
    however, OpenJDK (e.g. 22) still allocates arrays.
    
    The improvement is to access the arrays in case ByteBuffer allows so.
    DirectByteBuffer and read-only ByteBuffers forbid array access.
    vlsi committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    b97031e View commit details
    Browse the repository at this point in the history
  10. perf: optimize BlobOutputStream.write by buffering small consequent w…

    …rites, and allocating the buffer lazily
    
    Previously, each each blobOutput.write(byte[], ..) resulted in database call
    even in the case the write size is small. It could impact cases when users
    write in small chunks.
    At the same time, if they already write with big chunks, we should not create
    a buffer in BlobOutputStream, so now we create the buffer lazily.
    vlsi committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    bbcbc55 View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    e106168 View commit details
    Browse the repository at this point in the history
  12. perf: allow BlobOutputStream to resize its buffer up to 512KiB

    It enables to cover variety of incoming write requests, and it does not
    incur much overhead as the buffer grows lazily.
    vlsi committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    f7d82b8 View commit details
    Browse the repository at this point in the history
  13. doc: update documentation samples for accessing binary data

    We suggest using Blob APIs as they are standard.
    vlsi committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    e0277f1 View commit details
    Browse the repository at this point in the history