mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-01 02:41:39 -05:00
Disabled Sharp's internal cache to improve memory usage
refs https://sharp.pixelplumbing.com/api-utility#cache - Sharp has a 50MB cache by default, used within libvips, to increase the performance of transforming images - this isn't relevant to us because we should never be optimizing the same image as we check if the optimized image already exists - I presume there is also some extra overhead of using the cache because the memory doesn't seem to grow by 50MB - the memory usage comparison in Ghost is pretty drastic - uploading 10 images in serial w/ jemalloc: - with cache (default) = peak of 480MB, settles down to 330MB - disabling cache = peak of 270MB, settles down to 161MB - this commit disables the cache - also adds stubbing for the function in tests
This commit is contained in:
parent
5872147193
commit
eef85bba90
2 changed files with 6 additions and 0 deletions
|
@ -55,6 +55,10 @@ const unsafeResizeFromPath = (options = {}) => {
|
|||
*/
|
||||
const unsafeResizeFromBuffer = (originalBuffer, {width, height} = {}) => {
|
||||
const sharp = require('sharp');
|
||||
|
||||
// Disable the internal libvips cache - https://sharp.pixelplumbing.com/api-utility#cache
|
||||
sharp.cache(false);
|
||||
|
||||
return sharp(originalBuffer)
|
||||
.resize(width, height, {
|
||||
// CASE: dont make the image bigger than it was
|
||||
|
|
|
@ -66,6 +66,8 @@ describe('Transform', function () {
|
|||
return sharpInstance;
|
||||
});
|
||||
|
||||
sharp.cache = sinon.stub().returns({});
|
||||
|
||||
testUtils.modules.mockNonExistentModule('sharp', sharp);
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue