JVips icon indicating copy to clipboard operation
JVips copied to clipboard

Support for demand-driven write

Open bademux opened this issue 4 years ago • 3 comments

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.

bademux avatar Jul 25 '20 13:07 bademux

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

@dbouron Can you confirm?

warrenseine avatar Jul 27 '20 09:07 warrenseine

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.

dbouron avatar Jul 27 '20 13:07 dbouron

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)));
		}

bademux avatar Jul 27 '20 14:07 bademux