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 @@ -283,7 +283,10 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
283
283
}
284
284
285
285
private _internalWrite ( chunk : any , encoding : BufferEncoding ) {
286
- this . _chunks . push ( Buffer . from ( chunk , encoding ) ) ;
286
+ if ( ! this . streamCreator ) {
287
+ // Do not keep chunks around for streamed responses
288
+ this . _chunks . push ( Buffer . from ( chunk , encoding ) ) ;
289
+ }
287
290
this . push ( chunk , encoding ) ;
288
291
this . streamCreator ?. onWrite ?.( ) ;
289
292
}
@@ -306,7 +309,7 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
306
309
this . flushHeaders ( ) ;
307
310
}
308
311
// In some cases we might not have a store i.e. for example in the image optimization function
309
- // We may want to reconsider this in the future, it might be intersting to have access to this store everywhere
312
+ // We may want to reconsider this in the future, it might be interesting to have access to this store everywhere
310
313
globalThis . __openNextAls
311
314
?. getStore ( )
312
315
?. pendingPromiseRunner . add ( this . onEnd ( this . headers ) ) ;
You can’t perform that action at this time.
0 commit comments