You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "pjfanning (via GitHub)" <gi...@apache.org> on 2026/08/12 12:32:14 UTC

[PR] ByteString performance improvements (small) [pekko]

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: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] ByteString performance improvements (small) [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning merged PR #3427:
URL: https://github.com/apache/pekko/pull/3427


-- 
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: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org