divijvaidya opened a new pull request, #12967: URL: https://github.com/apache/kafka/pull/12967
`ListBuffer` should be preferred over `ArrayBuffer` in cases where: 1. No indexing is required. 2. The data structure is converted to Java's List from scala. `ListBuffer` has a [guaranteed constant time performance](https://docs.scala-lang.org/overviews/collections-2.13/performance-characteristics.html) for append operations which makes it a lucrative data structure for cases when we create a list and append multiple entries to it. This PR modifies usage of `ArrayBuffer` to `ListBuffer` in latency sensitive code path. To prove the usefulness of this change, I am attaching a CPU profile for an [open messaging benchmark](https://openmessaging.cloud/docs/benchmarks/). Please note that the self-time of the `ReplicaManager.fetchMessages()` reduced after this changes (depicted by the empty space in top of the frame for `ReplicaManager.fetchMessages()`. **Before this PR**  **After this PR**  Note: This PR piggybacks some general scala cleanup regarding usage of Optionals. -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org