Description
When uploading an image, the client-side media system generates 6-8 sub-sizes (thumbnail, medium, medium_large, large, 1536x1536, 2048x2048, scaled). Currently, each sub-size independently decodes the original compressed image via vips.Image.newFromBuffer(), resizes, and re-encodes.
For expensive formats like AVIF, decoding takes approximately 2 seconds per size. With 6-8 sub-sizes, this results in 10-14 seconds of redundant decode work.
Proposed Solution
Decode the source image once and reuse the decoded vips.Image for all sub-size resize operations using the thumbnailImage() instance method (which resizes from an already-decoded image without re-decoding).
The wasm-vips library supports this via:
vips.Image.newFromBuffer(buffer) — decode once (expensive)
image.thumbnailImage(width, options) — resize from decoded image (cheap)
Expected Performance Improvement
- Before: N × decode_time + N × resize_time + N × encode_time
- After: 1 × decode_time + N × resize_time + N × encode_time
- AVIF with 8 sizes (~2s decode): ~18s → ~4s (saving ~14s)
- JPEG with 8 sizes (~0.1s decode): marginal improvement, no regression
Related
Description
When uploading an image, the client-side media system generates 6-8 sub-sizes (thumbnail, medium, medium_large, large, 1536x1536, 2048x2048, scaled). Currently, each sub-size independently decodes the original compressed image via
vips.Image.newFromBuffer(), resizes, and re-encodes.For expensive formats like AVIF, decoding takes approximately 2 seconds per size. With 6-8 sub-sizes, this results in 10-14 seconds of redundant decode work.
Proposed Solution
Decode the source image once and reuse the decoded
vips.Imagefor all sub-size resize operations using thethumbnailImage()instance method (which resizes from an already-decoded image without re-decoding).The wasm-vips library supports this via:
vips.Image.newFromBuffer(buffer)— decode once (expensive)image.thumbnailImage(width, options)— resize from decoded image (cheap)Expected Performance Improvement
Related