File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
packages/open-next/src/http Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @opennextjs/aws " : minor
3
+ ---
4
+
5
+ perf(OpenNextResponse): do not store the chunks for streamed responses
6
+
7
+ There is no need to store the chunks for streamed responses.
8
+ Not storing the chunks allows saving memory.
9
+
10
+ Note that ` OpenNextHandler ` will now return an empty body for streamed responses.
Original file line number Diff line number Diff line change @@ -291,7 +291,10 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
291
291
}
292
292
293
293
private _internalWrite ( chunk : any , encoding : BufferEncoding ) {
294
- this . _chunks . push ( Buffer . from ( chunk , encoding ) ) ;
294
+ if ( ! this . streamCreator ) {
295
+ // Do not keep chunks around for streamed responses
296
+ this . _chunks . push ( Buffer . from ( chunk , encoding ) ) ;
297
+ }
295
298
this . push ( chunk , encoding ) ;
296
299
this . streamCreator ?. onWrite ?.( ) ;
297
300
}
@@ -314,7 +317,7 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
314
317
this . flushHeaders ( ) ;
315
318
}
316
319
// In some cases we might not have a store i.e. for example in the image optimization function
317
- // We may want to reconsider this in the future, it might be intersting to have access to this store everywhere
320
+ // We may want to reconsider this in the future, it might be interesting to have access to this store everywhere
318
321
globalThis . __openNextAls
319
322
?. getStore ( )
320
323
?. pendingPromiseRunner . add ( this . onEnd ( this . headers ) ) ;
You can’t perform that action at this time.
0 commit comments