Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize memory usage for Next.js Image #23015

Closed
wants to merge 1 commit into from

Conversation

shuding
Copy link
Member

@shuding shuding commented Mar 12, 2021

Description

We recently noticed that #22253 introduced some high memory usage issue for image-optimizer. Here's a simple way that I'm using to reproduce it:

  1. Create this simple Next.js app, which conditionally optimizes 30 images (each one is ~500kB).
  2. Build and start the app with inspector enabled, do a heap dump (1)
  3. Click the "Load 30 Images" button, scroll through the page to ensure all images are requested
  4. Do another head dump (2)

The memory usage increased from 19.3MB to 52.9MB (+274%), and most of the new allocated memory was taken by ArrayBuffer of ImageData, which should have been recollected after an image optimization request was done:

CleanShot 2021-03-12 at 13 45 14@2x

When looking at the reference chain I noticed that they're hold by jest-worker (Farm.js) inside the worker thread. Which is very likely a memory leak.

Root Cause

We are currently using jest-worker@24.9.0 (code) and as suggested in the screenshot above, it keeps task arguments inside a linked list called _last (code) but there's no removal action for it. So even with GC, the current head of that linked list won't be recollected as it will always have a reference.

After fixing that locally and with some further investigations, I noticed more memory related problems. The onStart and onEnd callbacks here and ...args will combine together as closures, and task will be passed to each worker (code) with another closure. Inside the worker there's another closure that keeps the previous values until _onProcessEnd (code).

That means, the arguments (and potentially the return value, due to Promise related closures) of the task we are doing won't be recollected unless the worker receives a new task, so all function references can be replaced.

An estimation of leaked memory size will be ~N ⨉ SizeOfOriginalImage ⨉ 2, where N is the number of workers (CPU cores), with some other overheads.

Fix

I first checked if the latest version jest-worker@next has fixed those issue, but unfortunately not. The latest version reimplemented the queue but still holds the reference in these closures internally. Although the same issue was roughly mentioned in the PR, the memory problem isn't fixed in my test app:

... This diff extracts the current queue implementation into the FifoQueue class and refactors the implementation to reduce the memory footprint. The current implementation added non-worker specific tasks to the queue of each worker. The result is that there are n * tasks queue entries where n is the number of workers for shared tasks. ...

It's not easy to get it fixed by doing more investigations and sending a patch to jest-worker, I suppose that Farm and Worker needs some non-trivial changes. And this problem will mostly only hurt us, because we are sending large objects as task arguments and results.

Given the priority of this issue inside the image optimizer, a work around is to pass some extra tasks to clear out the current queue head and replace those internal values inside each worker so the previous task can be GC'd completely. I added a no-op method and make sure it will be called N times after a Squoosh task.

CleanShot 2021-03-12 at 13 43 23@2x

With the fix the same app will not cause huge memory increase anymore (19.1MB → 19.9MB), and the ImageData and Buffer will be recollected successfully. There's small memory increase due to cache inside the HTTP module and extra loaded code.

Potentially fixes #22925.

Comment on lines +237 to +245
const etag = getHash([upstreamBuffer])
sendResponse(req, res, upstreamType, etag, upstreamBuffer)
await writeToCacheDir(
hashDir,
upstreamType,
expireAt,
etag,
upstreamBuffer
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved etag outside to avoid duplicate calculations, since it can increase CPU usage when the image is large. Also moved sendResponse earlier for a better TTFB.

@ijjk
Copy link
Member

ijjk commented Mar 12, 2021

Stats from current PR

Default Server Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary shuding/next.js fix-optimize-image-memory Change
buildDuration 13.5s 13.9s ⚠️ +342ms
nodeModulesSize 42.8 MB 42.8 MB ⚠️ +3.05 kB
Page Load Tests Overall increase ✓
vercel/next.js canary shuding/next.js fix-optimize-image-memory Change
/ failed reqs 0 0
/ total time (seconds) 2.496 2.451 -0.04
/ avg req/sec 1001.75 1019.88 +18.13
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.649 1.654 0
/error-in-render avg req/sec 1516.1 1511.55 ⚠️ -4.55
Client Bundles (main, webpack, commons)
vercel/next.js canary shuding/next.js fix-optimize-image-memory Change
677f882d2ed8..a2e7.js gzip 13.4 kB 13.4 kB
framework.HASH.js gzip 39 kB 39 kB
main-HASH.js gzip 6.65 kB 6.65 kB
webpack-HASH.js gzip 751 B 751 B
Overall change 59.8 kB 59.8 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary shuding/next.js fix-optimize-image-memory Change
polyfills-HASH.js gzip 31.3 kB 31.3 kB
Overall change 31.3 kB 31.3 kB
Client Pages
vercel/next.js canary shuding/next.js fix-optimize-image-memory Change
_app-fde3324..9dd1.js gzip 1.28 kB 1.28 kB
_error-af59f..582f.js gzip 3.46 kB 3.46 kB
amp-9716187d..0aa8.js gzip 536 B 536 B
hooks-107e90..74c7.js gzip 888 B 888 B
index-ac435c..ecf2.js gzip 227 B 227 B
link-c0d2c96..de48.js gzip 1.67 kB 1.67 kB
routerDirect..dc9d.js gzip 303 B 303 B
withRouter-6..0e02.js gzip 302 B 302 B
Overall change 8.66 kB 8.66 kB
Client Build Manifests
vercel/next.js canary shuding/next.js fix-optimize-image-memory Change
_buildManifest.js gzip 347 B 347 B
Overall change 347 B 347 B
Rendered Page Sizes
vercel/next.js canary shuding/next.js fix-optimize-image-memory Change
index.html gzip 611 B 611 B
link.html gzip 619 B 619 B
withRouter.html gzip 607 B 607 B
Overall change 1.84 kB 1.84 kB

Serverless Mode
General Overall increase ⚠️
vercel/next.js canary shuding/next.js fix-optimize-image-memory Change
buildDuration 15.7s 15.5s -175ms
nodeModulesSize 42.8 MB 42.8 MB ⚠️ +3.05 kB
Client Bundles (main, webpack, commons)
vercel/next.js canary shuding/next.js fix-optimize-image-memory Change
677f882d2ed8..a2e7.js gzip 13.4 kB 13.4 kB
framework.HASH.js gzip 39 kB 39 kB
main-HASH.js gzip 6.65 kB 6.65 kB
webpack-HASH.js gzip 751 B 751 B
Overall change 59.8 kB 59.8 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary shuding/next.js fix-optimize-image-memory Change
polyfills-HASH.js gzip 31.3 kB 31.3 kB
Overall change 31.3 kB 31.3 kB
Client Pages
vercel/next.js canary shuding/next.js fix-optimize-image-memory Change
_app-fde3324..9dd1.js gzip 1.28 kB 1.28 kB
_error-af59f..582f.js gzip 3.46 kB 3.46 kB
amp-9716187d..0aa8.js gzip 536 B 536 B
hooks-107e90..74c7.js gzip 888 B 888 B
index-ac435c..ecf2.js gzip 227 B 227 B
link-c0d2c96..de48.js gzip 1.67 kB 1.67 kB
routerDirect..dc9d.js gzip 303 B 303 B
withRouter-6..0e02.js gzip 302 B 302 B
Overall change 8.66 kB 8.66 kB
Client Build Manifests
vercel/next.js canary shuding/next.js fix-optimize-image-memory Change
_buildManifest.js gzip 347 B 347 B
Overall change 347 B 347 B
Serverless bundles
vercel/next.js canary shuding/next.js fix-optimize-image-memory Change
_error.js 1.02 MB 1.02 MB
404.html 2.67 kB 2.67 kB
500.html 2.65 kB 2.65 kB
amp.amp.html 10.6 kB 10.6 kB
amp.html 1.86 kB 1.86 kB
hooks.html 1.92 kB 1.92 kB
index.js 1.02 MB 1.02 MB
link.js 1.08 MB 1.08 MB
routerDirect.js 1.07 MB 1.07 MB
withRouter.js 1.07 MB 1.07 MB
Overall change 5.27 MB 5.27 MB

Webpack 5 Mode (Decrease detected ✓)
General Overall increase ⚠️
vercel/next.js canary shuding/next.js fix-optimize-image-memory Change
buildDuration 15.8s 16.1s ⚠️ +274ms
nodeModulesSize 42.8 MB 42.8 MB ⚠️ +3.05 kB
Page Load Tests Overall decrease ⚠️
vercel/next.js canary shuding/next.js fix-optimize-image-memory Change
/ failed reqs 0 0
/ total time (seconds) 2.478 2.38 -0.1
/ avg req/sec 1008.72 1050.39 +41.67
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.635 1.691 ⚠️ +0.06
/error-in-render avg req/sec 1528.99 1478.03 ⚠️ -50.96
Client Bundles (main, webpack, commons)
vercel/next.js canary shuding/next.js fix-optimize-image-memory Change
597-2bc2376a..203d.js gzip 13.3 kB 13.3 kB
framework.HASH.js gzip 39.3 kB 39.3 kB
main-HASH.js gzip 6.59 kB 6.59 kB
webpack-HASH.js gzip 954 B 954 B
Overall change 60.2 kB 60.2 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary shuding/next.js fix-optimize-image-memory Change
polyfills-HASH.js gzip 31.1 kB 31.1 kB
Overall change 31.1 kB 31.1 kB
Client Pages
vercel/next.js canary shuding/next.js fix-optimize-image-memory Change
_app-0c62a59..94b7.js gzip 1.26 kB 1.26 kB
_error-97d24..ed28.js gzip 3.38 kB 3.38 kB
amp-2926e4c2..9ccc.js gzip 536 B 536 B
hooks-1ed65b..8908.js gzip 902 B 902 B
index-6259b6..77d8.js gzip 230 B 230 B
link-b722682..14a4.js gzip 1.65 kB 1.65 kB
routerDirect..862a.js gzip 306 B 306 B
withRouter-4..76fd.js gzip 302 B 302 B
Overall change 8.57 kB 8.57 kB
Client Build Manifests
vercel/next.js canary shuding/next.js fix-optimize-image-memory Change
_buildManifest.js gzip 322 B 322 B
Overall change 322 B 322 B
Rendered Page Sizes
vercel/next.js canary shuding/next.js fix-optimize-image-memory Change
index.html gzip 585 B 585 B
link.html gzip 593 B 593 B
withRouter.html gzip 579 B 579 B
Overall change 1.76 kB 1.76 kB

Diffs

Diff for index.html
@@ -43,7 +43,7 @@
         "props": { "pageProps": {} },
         "page": "/",
         "query": {},
-        "buildId": "gNZXdTDVqNEYPYNiOeH1m",
+        "buildId": "3ZtABPLs8K9pcllagbI85",
         "isFallback": false,
         "gip": true
       }
@@ -77,11 +77,11 @@
       async=""
     ></script>
     <script
-      src="/_next/static/gNZXdTDVqNEYPYNiOeH1m/_buildManifest.js"
+      src="/_next/static/3ZtABPLs8K9pcllagbI85/_buildManifest.js"
       async=""
     ></script>
     <script
-      src="/_next/static/gNZXdTDVqNEYPYNiOeH1m/_ssgManifest.js"
+      src="/_next/static/3ZtABPLs8K9pcllagbI85/_ssgManifest.js"
       async=""
     ></script>
   </body>
Diff for link.html
@@ -48,7 +48,7 @@
         "props": { "pageProps": {} },
         "page": "/link",
         "query": {},
-        "buildId": "gNZXdTDVqNEYPYNiOeH1m",
+        "buildId": "3ZtABPLs8K9pcllagbI85",
         "isFallback": false,
         "gip": true
       }
@@ -82,11 +82,11 @@
       async=""
     ></script>
     <script
-      src="/_next/static/gNZXdTDVqNEYPYNiOeH1m/_buildManifest.js"
+      src="/_next/static/3ZtABPLs8K9pcllagbI85/_buildManifest.js"
       async=""
     ></script>
     <script
-      src="/_next/static/gNZXdTDVqNEYPYNiOeH1m/_ssgManifest.js"
+      src="/_next/static/3ZtABPLs8K9pcllagbI85/_ssgManifest.js"
       async=""
     ></script>
   </body>
Diff for withRouter.html
@@ -43,7 +43,7 @@
         "props": { "pageProps": {} },
         "page": "/withRouter",
         "query": {},
-        "buildId": "gNZXdTDVqNEYPYNiOeH1m",
+        "buildId": "3ZtABPLs8K9pcllagbI85",
         "isFallback": false,
         "gip": true
       }
@@ -77,11 +77,11 @@
       async=""
     ></script>
     <script
-      src="/_next/static/gNZXdTDVqNEYPYNiOeH1m/_buildManifest.js"
+      src="/_next/static/3ZtABPLs8K9pcllagbI85/_buildManifest.js"
       async=""
     ></script>
     <script
-      src="/_next/static/gNZXdTDVqNEYPYNiOeH1m/_ssgManifest.js"
+      src="/_next/static/3ZtABPLs8K9pcllagbI85/_ssgManifest.js"
       async=""
     ></script>
   </body>
Commit: f7ecdca

@ijjk
Copy link
Member

ijjk commented Mar 12, 2021

Failing test suites

Commit: f7ecdca

test/integration/image-optimizer/test/index.test.js

  • Image Optimizer > Server support w/o next.config.js > should use cached image file when parameters are the same
  • Image Optimizer > Server support w/o next.config.js > should use cached image file when parameters are the same for svg
  • Image Optimizer > Server support w/o next.config.js > should proxy-pass unsupported image types and should not cache file
  • Image Optimizer > Server support with next.config.js > should use cached image file when parameters are the same
  • Image Optimizer > Server support with next.config.js > should use cached image file when parameters are the same for svg
  • Image Optimizer > Server support with next.config.js > should proxy-pass unsupported image types and should not cache file
  • Image Optimizer > Serverless support with next.config.js > should use cached image file when parameters are the same
  • Image Optimizer > Serverless support with next.config.js > should use cached image file when parameters are the same for svg
  • Image Optimizer > Serverless support with next.config.js > should use cached image file when parameters are the same for animated gif
  • Image Optimizer > Serverless support with next.config.js > should proxy-pass unsupported image types and should not cache file
  • Image Optimizer > dev support w/o next.config.js > should use cached image file when parameters are the same
  • Image Optimizer > dev support w/o next.config.js > should use cached image file when parameters are the same for svg
  • Image Optimizer > dev support w/o next.config.js > should use cached image file when parameters are the same for animated gif
  • Image Optimizer > dev support w/o next.config.js > should proxy-pass unsupported image types and should not cache file
  • Image Optimizer > dev support with next.config.js > should use cached image file when parameters are the same
  • Image Optimizer > dev support with next.config.js > should use cached image file when parameters are the same for svg
  • Image Optimizer > dev support with next.config.js > should proxy-pass unsupported image types and should not cache file
Expand output

● Image Optimizer › dev support w/o next.config.js › should use cached image file when parameters are the same

ENOENT: no such file or directory, scandir '/home/runner/work/next.js/next.js/test/integration/image-optimizer/.next/cache/images'

● Image Optimizer › dev support w/o next.config.js › should use cached image file when parameters are the same for svg

ENOENT: no such file or directory, scandir '/home/runner/work/next.js/next.js/test/integration/image-optimizer/.next/cache/images'

● Image Optimizer › dev support w/o next.config.js › should use cached image file when parameters are the same for animated gif

ENOENT: no such file or directory, scandir '/home/runner/work/next.js/next.js/test/integration/image-optimizer/.next/cache/images'

● Image Optimizer › dev support w/o next.config.js › should proxy-pass unsupported image types and should not cache file

expect(received).toStrictEqual(expected) // deep equality

- Expected  - 1
+ Received  + 3

@@ -3,7 +3,9 @@
      "1615558100266.ytF6PNFjoFGjThysPbv18JvQTUSZEbceiwhiUe15gms=.webp": "file",
    },
    "JaVHDYyrruWxL-7XESZwwXMsK8gMbgsBXJTIVWNwZS0=": Object {
      "1615558100250.CXZ99T+7Ygxk6-tOxhVDMs3cEHVNX1+w7hkcDjgeFp8=.gif": "file",
    },
-   "kdlFi0b8l31JY+NYyNYx-dgMaAnz927J7Yrg8oIBnfU=": Object {},
+   "kdlFi0b8l31JY+NYyNYx-dgMaAnz927J7Yrg8oIBnfU=": Object {
+     "1615558100467.tnlzwizOQncYAh2j+ql91HlOvA7Sr3nFiO9E0YNJw2I=.webp": "file",
+   },
  }

  467 | 
  468 |     const json2 = await fsToJson(imagesDir)
> 469 |     expect(json2).toStrictEqual(json1)
      |                   ^
  470 |   })
  471 | 
  472 |   it('should not resize if requested width is larger than original source image', async () => {

  at Object.<anonymous> (integration/image-optimizer/test/index.test.js:469:19)

● Image Optimizer › dev support with next.config.js › should use cached image file when parameters are the same

ENOENT: no such file or directory, scandir '/home/runner/work/next.js/next.js/test/integration/image-optimizer/.next/cache/images'

● Image Optimizer › dev support with next.config.js › should use cached image file when parameters are the same for svg

expect(received).toStrictEqual(expected) // deep equality

- Expected  - 0
+ Received  + 3

  Object {
+   "3ni1QvE6-QDjrV5fp-vdhDyNa7WfzPGdXMvwaL69Ido=": Object {
+     "1615558111380.uMPNuid+hcs5LfgZx1sQD+pxE9fvTG6vWVz13fUoRVM=.svg": "file",
+   },
    "CK+X6v2fq99rlh7QpTPTHrd+c82A+77N4Ql6r-wVnv8=": Object {
      "1615558111290.7Wc9fak1Ftz3i52Z54SYDwvdc6eFhMvBevpqX8aMrVE=.webp": "file",
    },
  }

  397 |     expect(res2.headers.get('Content-Type')).toBe('image/svg+xml')
  398 |     const json2 = await fsToJson(imagesDir)
> 399 |     expect(json2).toStrictEqual(json1)
      |                   ^
  400 |   })
  401 | 
  402 |   it('should use cached image file when parameters are the same for animated gif', async () => {

  at Object.<anonymous> (integration/image-optimizer/test/index.test.js:399:19)

● Image Optimizer › dev support with next.config.js › should proxy-pass unsupported image types and should not cache file

expect(received).toStrictEqual(expected) // deep equality

- Expected  - 0
+ Received  + 3

@@ -1,6 +1,9 @@
  Object {
+   "3K8socP9c38gSvNI+Vg7FDoNzkks+ENPgBA-88xIXBM=": Object {
+     "1615558111520.iH250BNNYWjgzFXY5cUMjhp6JUiLb4yVob-LBWDjWdw=.webp": "file",
+   },
    "Og2cRWTbuNrwyneqVICk+RzVQqmd+n31beEWacVixhw=": Object {
      "1615558111416.E7lTa3Mc+gO7ukdj+IBA5915i87FVpXYWdSCEeYkZOU=.webp": "file",
    },
    "k4Mj5jogxEvOSHeRkCuOSUKnHA6MSMVCBVXiv09+qUs=": Object {
      "1615558111403.CXZ99T+7Ygxk6-tOxhVDMs3cEHVNX1+w7hkcDjgeFp8=.gif": "file",

  467 | 
  468 |     const json2 = await fsToJson(imagesDir)
> 469 |     expect(json2).toStrictEqual(json1)
      |                   ^
  470 |   })
  471 | 
  472 |   it('should not resize if requested width is larger than original source image', async () => {

  at Object.<anonymous> (integration/image-optimizer/test/index.test.js:469:19)

● Image Optimizer › Server support w/o next.config.js › should use cached image file when parameters are the same

expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  372 |     expect(res1.headers.get('Content-Type')).toBe('image/webp')
  373 |     const json1 = await fsToJson(imagesDir)
> 374 |     expect(Object.keys(json1).length).toBe(1)
      |                                       ^
  375 | 
  376 |     const res2 = await fetchViaHTTP(appPort, '/_next/image', query, opts)
  377 |     expect(res2.status).toBe(200)

  at Object.<anonymous> (integration/image-optimizer/test/index.test.js:374:39)

● Image Optimizer › Server support w/o next.config.js › should use cached image file when parameters are the same for svg

expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  391 |     expect(res1.headers.get('Content-Type')).toBe('image/svg+xml')
  392 |     const json1 = await fsToJson(imagesDir)
> 393 |     expect(Object.keys(json1).length).toBe(1)
      |                                       ^
  394 | 
  395 |     const res2 = await fetchViaHTTP(appPort, '/_next/image', query, opts)
  396 |     expect(res2.status).toBe(200)

  at Object.<anonymous> (integration/image-optimizer/test/index.test.js:393:39)

● Image Optimizer › Server support w/o next.config.js › should proxy-pass unsupported image types and should not cache file

expect(received).toStrictEqual(expected) // deep equality

- Expected  - 0
+ Received  + 3

@@ -3,6 +3,9 @@
      "1615558123682.ytF6PNFjoFGjThysPbv18JvQTUSZEbceiwhiUe15gms=.webp": "file",
    },
    "JaVHDYyrruWxL-7XESZwwXMsK8gMbgsBXJTIVWNwZS0=": Object {
      "1615558123671.CXZ99T+7Ygxk6-tOxhVDMs3cEHVNX1+w7hkcDjgeFp8=.gif": "file",
    },
+   "kdlFi0b8l31JY+NYyNYx-dgMaAnz927J7Yrg8oIBnfU=": Object {
+     "1615558123815.tnlzwizOQncYAh2j+ql91HlOvA7Sr3nFiO9E0YNJw2I=.webp": "file",
+   },
  }

  467 | 
  468 |     const json2 = await fsToJson(imagesDir)
> 469 |     expect(json2).toStrictEqual(json1)
      |                   ^
  470 |   })
  471 | 
  472 |   it('should not resize if requested width is larger than original source image', async () => {

  at Object.<anonymous> (integration/image-optimizer/test/index.test.js:469:19)

● Image Optimizer › Server support with next.config.js › should use cached image file when parameters are the same

ENOENT: no such file or directory, scandir '/home/runner/work/next.js/next.js/test/integration/image-optimizer/.next/cache/images'

● Image Optimizer › Server support with next.config.js › should use cached image file when parameters are the same for svg

expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 2

  391 |     expect(res1.headers.get('Content-Type')).toBe('image/svg+xml')
  392 |     const json1 = await fsToJson(imagesDir)
> 393 |     expect(Object.keys(json1).length).toBe(1)
      |                                       ^
  394 | 
  395 |     const res2 = await fetchViaHTTP(appPort, '/_next/image', query, opts)
  396 |     expect(res2.status).toBe(200)

  at Object.<anonymous> (integration/image-optimizer/test/index.test.js:393:39)

● Image Optimizer › Server support with next.config.js › should proxy-pass unsupported image types and should not cache file

expect(received).toStrictEqual(expected) // deep equality

- Expected  - 1
+ Received  + 3

@@ -1,7 +1,9 @@
  Object {
-   "32WtPcB9u1yhOB-VKZZawUZjtqcS2G5ThhdB--f4fTA=": Object {},
+   "32WtPcB9u1yhOB-VKZZawUZjtqcS2G5ThhdB--f4fTA=": Object {
+     "1615558132668.CqtzFjWVB7FDnMtvCNJj3e6bRMLVgmdQv9XDti2STgg=.webp": "file",
+   },
    "8pF0bm6N4FpSmxmi8RwcTZ9Wc55u9lOt+wNuRIb0H1A=": Object {
      "1615558132568.7wUnTW44colxJ1Xcy2UlL4c9nQHZalAGOHDszTImnvw=.webp": "file",
    },
    "GLeYcGJqGjSShUNkObG3dtOLEy-E9G13urV0sO3qRNQ=": Object {
      "1615558132560.CXZ99T+7Ygxk6-tOxhVDMs3cEHVNX1+w7hkcDjgeFp8=.gif": "file",

  467 | 
  468 |     const json2 = await fsToJson(imagesDir)
> 469 |     expect(json2).toStrictEqual(json1)
      |                   ^
  470 |   })
  471 | 
  472 |   it('should not resize if requested width is larger than original source image', async () => {

  at Object.<anonymous> (integration/image-optimizer/test/index.test.js:469:19)

● Image Optimizer › Serverless support with next.config.js › should use cached image file when parameters are the same

ENOENT: no such file or directory, scandir '/home/runner/work/next.js/next.js/test/integration/image-optimizer/.next/cache/images'

● Image Optimizer › Serverless support with next.config.js › should use cached image file when parameters are the same for svg

expect(received).toStrictEqual(expected) // deep equality

- Expected  - 0
+ Received  + 3

  Object {
+   "QS+H62rpXf6iVRCixaMXDmmWSvpAyxVfZHIOgdrHJIc=": Object {
+     "1615558143043.uMPNuid+hcs5LfgZx1sQD+pxE9fvTG6vWVz13fUoRVM=.svg": "file",
+   },
    "nDcue+CQ7zERS-R1Lj0fbboCK1b5cHqKOkS-msy4rPU=": Object {
      "1615558142890.rbsmggVNqhyK3dZHo91hz0KmPRc6L3KVfm2dv3SkIck=.webp": "file",
    },
  }

  397 |     expect(res2.headers.get('Content-Type')).toBe('image/svg+xml')
  398 |     const json2 = await fsToJson(imagesDir)
> 399 |     expect(json2).toStrictEqual(json1)
      |                   ^
  400 |   })
  401 | 
  402 |   it('should use cached image file when parameters are the same for animated gif', async () => {

  at Object.<anonymous> (integration/image-optimizer/test/index.test.js:399:19)

● Image Optimizer › Serverless support with next.config.js › should use cached image file when parameters are the same for animated gif

expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  410 |     expect(res1.headers.get('Content-Type')).toBe('image/gif')
  411 |     const json1 = await fsToJson(imagesDir)
> 412 |     expect(Object.keys(json1).length).toBe(1)
      |                                       ^
  413 | 
  414 |     const res2 = await fetchViaHTTP(appPort, '/_next/image', query, opts)
  415 |     expect(res2.status).toBe(200)

  at Object.<anonymous> (integration/image-optimizer/test/index.test.js:412:39)

● Image Optimizer › Serverless support with next.config.js › should proxy-pass unsupported image types and should not cache file

expect(received).toStrictEqual(expected) // deep equality

- Expected  - 0
+ Received  + 3

  Object {
    "3TOwy2sxalDMn+52SUdDGPKZgr44secypS95-D074qw=": Object {
      "1615558143063.CXZ99T+7Ygxk6-tOxhVDMs3cEHVNX1+w7hkcDjgeFp8=.gif": "file",
    },
+   "9nOo4-NKKu1NPOR6lhoGYRHpu9a+bmNEaMFGe4efVoQ=": Object {
+     "1615558143226.NT7XS6+Dg7u4AqhrnCURv99z3VKfWe4oRwC4tyzLXM4=.webp": "file",
+   },
    "pUStDCnOcNSguNblcjQAnSyNgA5WFFnoWfRYTNL5MmM=": Object {
      "1615558143068.mqZgSxxbu2Nt-QWs0z570N1TV84z128AJaTylJ9elE4=.webp": "file",
    },
  }

  467 | 
  468 |     const json2 = await fsToJson(imagesDir)
> 469 |     expect(json2).toStrictEqual(json1)
      |                   ^
  470 |   })
  471 | 
  472 |   it('should not resize if requested width is larger than original source image', async () => {

  at Object.<anonymous> (integration/image-optimizer/test/index.test.js:469:19)

@shuding shuding closed this Mar 12, 2021
@shuding shuding deleted the fix-optimize-image-memory branch March 12, 2021 14:53
@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10.0.8 next/image high memory use
2 participants