criteo / JVips

Java wrapper for libvips using JNI.
Apache License 2.0
72 stars 41 forks source link

Support for demand-driven write #39

Open bademux opened 4 years ago

bademux commented 4 years ago

Hi, Nice wrapper, thanks! Looks like I need some help with understanding "[demand-driven feature]( https://github.com/libvips/libvips/wiki/Why-is-libvips-quick)". As far as I understand libvips can process image without loading it to RAM fully. For Jvips it is possible to pass MappedByteBuffer as input; But how about output? Does it mean JVips doesn't support this feature or I missed the point of "demand-driven" and it applies only for reading.

Thanks. B.

warrenseine commented 4 years ago

Yes, from my understanding, JVips doesn't support it, but it would be a nice improvement.

@dbouron Can you confirm?

dbouron commented 4 years ago

Yes, we didn't implement it because when we measured cpu performance between mapped and byte array, the results were very similar. Thus, we decided to keep a straightforward implementation for our app. We didn't measure the impact on the memory, it would be a nice to have. If we implement this feature, we must provide benchmark on the memory consumption.

bademux commented 4 years ago

thanks! btw, here the small snippet how I test JVips Read

        try (FileChannel ch = Files.newByteChannel(path, READ);
             VipsImage image = new VipsImage(ch.map(READ_ONLY, 0, ch.size()), (int) ch.size())) {
            ...
        }

Write

        try (FileChannel ch = Files.newByteChannel(path, WRITE)) {
            os.write(ByteBuffer.wrap(img.writeToArray(VipsImageFormat.JPG, true)));
        }