pjfanning opened a new pull request, #3427:
URL: https://github.com/apache/pekko/pull/3427

   Assisted by Claude AI.
   
   These 2 low impact changes should have a reasonable perf benefit.
   
   1. ByteStrings.iterator uses LazyList — significant overhead
   
   File: ByteString.scala:1458
   override def iterator: ByteIterator.MultiByteArrayIterator =
     ByteIterator.MultiByteArrayIterator(bytestrings.to(LazyList).map { 
_.iterator })
   
   LazyList has per-element thunk allocation and synchronization overhead. 
Since bytestrings is already a Vector (random-access), a plain Iterator is 
sufficient:
   
   override def iterator: ByteIterator.MultiByteArrayIterator =
     ByteIterator.MultiByteArrayIterator(bytestrings.iterator.map(_.iterator))
   
   This eliminates lazy evaluation machinery that buys nothing here — the 
fragments are already materialized in the Vector.
   
   ByteStrings.iterator: Replaced bytestrings.to(LazyList).map(_.iterator) with 
bytestrings.iterator.map(_.iterator).toList. The LazyList allocated thunks for 
each element access despite the fragments already being materialized in the 
Vector. A plain List is a LinearSeq (which MultiByteArrayIterator requires) and 
avoids the per-element lazy evaluation overhead.
   
   2. ByteStrings.map: Changed bs(i) to bs.byteAtUnchecked(i). Since the loop 
already constrains i to 0 until bs.length, the bounds check in 
ByteString1.apply was redundant. byteAtUnchecked skips the checkRangeConvert 
call (bounds check + offset arithmetic) on every byte.
   


-- 
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