Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Avoid forwarding method on ArrayDequeue in BatchingExecutor. #1688

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package org.apache.pekko.dispatch
import org.apache.pekko
import pekko.annotation.InternalApi

import java.util.ArrayDeque
import java.util.concurrent.Executor
import scala.annotation.tailrec
import scala.concurrent._
Expand Down Expand Up @@ -67,10 +66,10 @@ private[pekko] trait BatchingExecutor extends Executor {
// invariant: if "_tasksLocal.get ne null" then we are inside Batch.run; if it is null, we are outside
private[this] val _tasksLocal = new ThreadLocal[AbstractBatch]()

private[this] abstract class AbstractBatch extends ArrayDeque[Runnable](4) with Runnable {
private[this] abstract class AbstractBatch extends java.util.ArrayDeque[Runnable](4) with Runnable {
@tailrec final def processBatch(batch: AbstractBatch): Unit =
if ((batch eq this) && !batch.isEmpty) {
batch.poll().run()
batch.pollFirst().run()
He-Pin marked this conversation as resolved.
Show resolved Hide resolved
processBatch(_tasksLocal.get) // If this is null, then we have been using managed blocking, so bail out
}

Expand All @@ -85,7 +84,7 @@ private[pekko] trait BatchingExecutor extends Executor {
}

private[this] final class Batch extends AbstractBatch {
override final def run: Unit = {
override final def run(): Unit = {
require(_tasksLocal.get eq null)
_tasksLocal.set(this) // Install ourselves as the current batch
try processBatch(this)
Expand Down
Loading