File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
packages/open-next/src/http Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @opennextjs/aws " : patch
3+ ---
4+
5+ perf: avoid unnecessary buffer copy in internalWrite
Original file line number Diff line number Diff line change @@ -285,13 +285,18 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
285285 }
286286
287287 private _internalWrite ( chunk : any , encoding : BufferEncoding ) {
288- const buffer = Buffer . from ( chunk , encoding ) ;
288+ // When encoding === 'buffer', chunk is already a Buffer
289+ // and does not need to be converted again.
290+ // @ts -expect-error TS2367 'encoding' can be 'buffer', but it's not in the
291+ // official type definition
292+ const buffer = encoding === "buffer" ? chunk : Buffer . from ( chunk , encoding ) ;
289293 this . bodyLength += buffer . length ;
290294 if ( this . streamCreator ?. retainChunks !== false ) {
291295 // Avoid keeping chunks around when the `StreamCreator` supports it to save memory
292296 this . _chunks . push ( buffer ) ;
293297 }
294- this . push ( chunk , encoding ) ;
298+ // No need to pass the encoding for buffers
299+ this . push ( buffer ) ;
295300 this . streamCreator ?. onWrite ?.( ) ;
296301 }
297302
You can’t perform that action at this time.
0 commit comments