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

   The ByteString2 class (2-fragment ByteString) had cross-boundary read 
methods that used 8 individual byteAt calls for Long reads. Each byteAt call 
has a branch (check which fragment). The optimization:
   
   - Long reads (BE/LE): Build two sub-long values from byteAtUnchecked calls 
(which skip the bounds check branch) and combine them with bitwise OR. This 
reduces the branch overhead from 8 per Long to 8 virtual calls (one per byte, 
no extra branching per call) plus pure arithmetic assembly.
   - Short/Int reads: Kept using byteAt via SWARUtil helper methods. With only 
2-4 bytes needed, the branch overhead is minimal and not worth adding 
complexity.
   
   Why not direct array access: The first/second fields are typed as ByteString 
(trait), and .bytes/.startIndex are private[pekko] on the concrete subclasses 
but not accessible from the nested ByteString2 class context. byteAtUnchecked 
provides the same bounds-check-skipping benefit through virtual dispatch.
   
   Files changed:
   - ByteStrings.iterator: LazyList → List (eliminates per-element thunk 
allocation)
   - ByteStrings.slice: Direct fragment collection instead of drop+dropRight
   - ByteStrings.apply: Binary search instead of linear scan
   - ByteStrings.map: Uses byteAtUnchecked
   - ByteString2.readLong{BE,LE}Unchecked: byteAtUnchecked-based assembly 
instead of individual byteAt calls


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