Switch to sequential read as default where possible

This commit is contained in:
Lovell Fuller 2023-01-15 18:43:50 +00:00
parent 081debd055
commit a1e464cc5e
6 changed files with 14 additions and 11 deletions

View File

@ -25,7 +25,7 @@ Implements the [stream.Duplex](http://nodejs.org/api/stream.html#stream_class_st
| [options.failOn] | <code>string</code> | <code>&quot;&#x27;warning&#x27;&quot;</code> | when to abort processing of invalid pixel data, one of (in order of sensitivity): 'none' (least), 'truncated', 'error' or 'warning' (most), highers level imply lower levels, invalid metadata will always abort. | | [options.failOn] | <code>string</code> | <code>&quot;&#x27;warning&#x27;&quot;</code> | when to abort processing of invalid pixel data, one of (in order of sensitivity): 'none' (least), 'truncated', 'error' or 'warning' (most), highers level imply lower levels, invalid metadata will always abort. |
| [options.limitInputPixels] | <code>number</code> \| <code>boolean</code> | <code>268402689</code> | Do not process input images where the number of pixels (width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted. An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF). | | [options.limitInputPixels] | <code>number</code> \| <code>boolean</code> | <code>268402689</code> | Do not process input images where the number of pixels (width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted. An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF). |
| [options.unlimited] | <code>boolean</code> | <code>false</code> | Set this to `true` to remove safety features that help prevent memory exhaustion (JPEG, PNG, SVG, HEIF). | | [options.unlimited] | <code>boolean</code> | <code>false</code> | Set this to `true` to remove safety features that help prevent memory exhaustion (JPEG, PNG, SVG, HEIF). |
| [options.sequentialRead] | <code>boolean</code> | <code>false</code> | Set this to `true` to use sequential rather than random access where possible. This can reduce memory usage and might improve performance on some systems. | | [options.sequentialRead] | <code>boolean</code> | <code>true</code> | Set this to `false` to use random access rather than sequential read. Some operations will do this automatically. |
| [options.density] | <code>number</code> | <code>72</code> | number representing the DPI for vector images in the range 1 to 100000. | | [options.density] | <code>number</code> | <code>72</code> | number representing the DPI for vector images in the range 1 to 100000. |
| [options.pages] | <code>number</code> | <code>1</code> | number of pages to extract for multi-page input (GIF, WebP, AVIF, TIFF, PDF), use -1 for all pages. | | [options.pages] | <code>number</code> | <code>1</code> | number of pages to extract for multi-page input (GIF, WebP, AVIF, TIFF, PDF), use -1 for all pages. |
| [options.page] | <code>number</code> | <code>0</code> | page number to start extracting from for multi-page input (GIF, WebP, AVIF, TIFF, PDF), zero based. | | [options.page] | <code>number</code> | <code>0</code> | page number to start extracting from for multi-page input (GIF, WebP, AVIF, TIFF, PDF), zero based. |

View File

@ -6,6 +6,8 @@ Requires libvips v8.14.0
### v0.32.0 - TBD ### v0.32.0 - TBD
* Default to using sequential rather than random access read where possible.
* Replace GIF output `optimise` / `optimize` option with `reuse`. * Replace GIF output `optimise` / `optimize` option with `reuse`.
* Add `progressive` option to GIF output for interlacing. * Add `progressive` option to GIF output for interlacing.

View File

@ -124,8 +124,7 @@ const debuglog = util.debuglog('sharp');
* (width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted. * (width x height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted.
* An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF). * An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF).
* @param {boolean} [options.unlimited=false] - Set this to `true` to remove safety features that help prevent memory exhaustion (JPEG, PNG, SVG, HEIF). * @param {boolean} [options.unlimited=false] - Set this to `true` to remove safety features that help prevent memory exhaustion (JPEG, PNG, SVG, HEIF).
* @param {boolean} [options.sequentialRead=false] - Set this to `true` to use sequential rather than random access where possible. * @param {boolean} [options.sequentialRead=true] - Set this to `false` to use random access rather than sequential read. Some operations will do this automatically.
* This can reduce memory usage and might improve performance on some systems.
* @param {number} [options.density=72] - number representing the DPI for vector images in the range 1 to 100000. * @param {number} [options.density=72] - number representing the DPI for vector images in the range 1 to 100000.
* @param {number} [options.pages=1] - number of pages to extract for multi-page input (GIF, WebP, AVIF, TIFF, PDF), use -1 for all pages. * @param {number} [options.pages=1] - number of pages to extract for multi-page input (GIF, WebP, AVIF, TIFF, PDF), use -1 for all pages.
* @param {number} [options.page=0] - page number to start extracting from for multi-page input (GIF, WebP, AVIF, TIFF, PDF), zero based. * @param {number} [options.page=0] - page number to start extracting from for multi-page input (GIF, WebP, AVIF, TIFF, PDF), zero based.

View File

@ -36,7 +36,7 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
failOn: 'warning', failOn: 'warning',
limitInputPixels: Math.pow(0x3FFF, 2), limitInputPixels: Math.pow(0x3FFF, 2),
unlimited: false, unlimited: false,
sequentialRead: false sequentialRead: true
}; };
if (is.string(input)) { if (is.string(input)) {
// filesystem // filesystem

View File

@ -399,7 +399,7 @@ class PipelineWorker : public Napi::AsyncWorker {
} }
// Join additional color channels to the image // Join additional color channels to the image
if (baton->joinChannelIn.size() > 0) { if (!baton->joinChannelIn.empty()) {
VImage joinImage; VImage joinImage;
sharp::ImageType joinImageType = sharp::ImageType::UNKNOWN; sharp::ImageType joinImageType = sharp::ImageType::UNKNOWN;
@ -504,7 +504,7 @@ class PipelineWorker : public Napi::AsyncWorker {
} }
// Affine transform // Affine transform
if (baton->affineMatrix.size() > 0) { if (!baton->affineMatrix.empty()) {
MultiPageUnsupported(nPages, "Affine"); MultiPageUnsupported(nPages, "Affine");
std::vector<double> background; std::vector<double> background;
std::tie(image, background) = sharp::ApplyAlpha(image, baton->affineBackground, shouldPremultiplyAlpha); std::tie(image, background) = sharp::ApplyAlpha(image, baton->affineBackground, shouldPremultiplyAlpha);
@ -1644,9 +1644,11 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
baton->trimThreshold > 0.0 || baton->trimThreshold > 0.0 ||
baton->normalise || baton->normalise ||
baton->position == 16 || baton->position == 17 || baton->position == 16 || baton->position == 17 ||
baton->angle % 360 != 0 || baton->angle != 0 ||
fmod(baton->rotationAngle, 360.0) != 0.0 || baton->rotationAngle != 0.0 ||
baton->useExifOrientation baton->tileAngle != 0 ||
baton->useExifOrientation ||
!baton->affineMatrix.empty()
) { ) {
baton->input->access = VIPS_ACCESS_RANDOM; baton->input->access = VIPS_ACCESS_RANDOM;
} }

View File

@ -535,10 +535,10 @@ async.series({
} }
}); });
} }
}).add('sharp-sequentialRead', { }).add('sharp-random-access-read', {
defer: true, defer: true,
fn: function (deferred) { fn: function (deferred) {
sharp(inputJpgBuffer, { sequentialRead: true }) sharp(inputJpgBuffer, { sequentialRead: false })
.resize(width, height) .resize(width, height)
.toBuffer(function (err) { .toBuffer(function (err) {
if (err) { if (err) {