He-Pin commented on code in PR #311:
URL: 
https://github.com/apache/incubator-pekko-http/pull/311#discussion_r1311781340


##########
http-core/src/main/scala/org/apache/pekko/http/impl/engine/ws/MessageToFrameRenderer.scala:
##########
@@ -35,20 +34,10 @@ private[http] object MessageToFrameRenderer {
       Source.single(FrameEvent.fullFrame(opcode, None, data, fin = true))
 
     def streamedFrames[M](opcode: Opcode, data: Source[ByteString, M]): 
Source[FrameStart, Any] =
-      data.via(StreamUtils.statefulMap(() => {
-        var isFirst = true
-
-        { data =>
-          val frameOpcode =
-            if (isFirst) {
-              isFirst = false
-              opcode
-            } else Opcode.Continuation
-
-          FrameEvent.fullFrame(frameOpcode, None, data, fin = false)
-        }
-      })) ++
-      Source.single(FrameEvent.emptyLastContinuationFrame)
+      data.statefulMap(() => true)((isFirst, data) => {
+          val frameOpcode = if (isFirst) opcode else Opcode.Continuation
+          (false, FrameEvent.fullFrame(frameOpcode, None, data, fin = false))

Review Comment:
   ```
   [info] Benchmark                                                Mode  Cnt    
     Score        Error  Units
   [info] MessageToFrameRendererBenchmark.benchNewStreamedFrames  thrpt   10  
15148931.446 锟斤拷  99406.646  ops/s
   [info] MessageToFrameRendererBenchmark.benchOldStreamedFrames  thrpt   10  
13296638.654 锟斤拷 553890.759  ops/s
   ```
   
![image](https://github.com/apache/incubator-pekko-http/assets/501740/31efec0b-f8ff-4ec0-8046-be12b16d099c)
   



##########
http-core/src/main/scala/org/apache/pekko/http/impl/engine/ws/MessageToFrameRenderer.scala:
##########
@@ -35,20 +34,10 @@ private[http] object MessageToFrameRenderer {
       Source.single(FrameEvent.fullFrame(opcode, None, data, fin = true))
 
     def streamedFrames[M](opcode: Opcode, data: Source[ByteString, M]): 
Source[FrameStart, Any] =
-      data.via(StreamUtils.statefulMap(() => {
-        var isFirst = true
-
-        { data =>
-          val frameOpcode =
-            if (isFirst) {
-              isFirst = false
-              opcode
-            } else Opcode.Continuation
-
-          FrameEvent.fullFrame(frameOpcode, None, data, fin = false)
-        }
-      })) ++
-      Source.single(FrameEvent.emptyLastContinuationFrame)
+      data.statefulMap(() => true)((isFirst, data) => {
+          val frameOpcode = if (isFirst) opcode else Opcode.Continuation
+          (false, FrameEvent.fullFrame(frameOpcode, None, data, fin = false))

Review Comment:
   ```
   [info] Benchmark                                                Mode  Cnt    
     Score        Error  Units
   [info] MessageToFrameRendererBenchmark.benchNewStreamedFrames  thrpt   10  
15148931.446 锟斤拷  99406.646  ops/s
   [info] MessageToFrameRendererBenchmark.benchOldStreamedFrames  thrpt   10  
13296638.654 锟斤拷 553890.759  ops/s
   ```
   
![image](https://github.com/apache/incubator-pekko-http/assets/501740/31efec0b-f8ff-4ec0-8046-be12b16d099c)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to