He-Pin commented on code in PR #311:
URL:
https://github.com/apache/incubator-pekko-http/pull/311#discussion_r1311622129
##########
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:
Thanks, there is an benchmark for using the `statefulMap` to implement the
`zipWithIndex` which shows no much harm but get better performance.
And it was ` f(i) :: Nil`, plus a `iterator` creation too, I think it's
nearly the same.
```
Jmh/run -i 3 -wi 3 -f1 -t1 .*ZipWithIndexBenchmark.*
[info] Benchmark Mode Cnt
Score Error Units
[info] ZipWithIndexBenchmark.benchNewZipWithIndex thrpt 3
6501714129.146 锟斤拷 4044285303.660 ops/s
[info] ZipWithIndexBenchmark.benchOldZipWithIndex thrpt 3
6146967182.338 锟斤拷 801852805.114 ops/s
```
That's why I dear to change this.
I can submit a benchmark after worktime to verify this.
--
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]