Skip to content

Make use of eq and ne.#1994

Merged
He-Pin merged 2 commits into
apache:mainfrom
He-Pin:eq
Aug 3, 2025
Merged

Make use of eq and ne.#1994
He-Pin merged 2 commits into
apache:mainfrom
He-Pin:eq

Conversation

@He-Pin

@He-Pin He-Pin commented Aug 2, 2025

Copy link
Copy Markdown
Member

Motivation:
eq and ne are more performance

@He-Pin
He-Pin requested review from Copilot and pjfanning and removed request for Copilot August 2, 2025 10:41
@He-Pin He-Pin added this to the 2.0.x milestone Aug 2, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes performance by replacing ==/!= equality comparisons with reference equality checks (eq/ne) when comparing against null. Reference equality is more performant than value equality as it only checks if two references point to the same object in memory, rather than potentially calling the equals method.

  • Replaces == null with eq null throughout the codebase
  • Replaces != null with ne null throughout the codebase
  • Adds parentheses around compound conditions for clarity when needed

Reviewed Changes

Copilot reviewed 84 out of 84 changed files in this pull request and generated no comments.

Show a summary per file
File Description
testkit/src/main/scala/org/apache/pekko/testkit/javadsl/EventFilter.scala Updates null comparison in exception type check
testkit/src/main/scala/org/apache/pekko/testkit/TestKit.scala Updates null comparison in queue polling logic
stream/src/main/scala/org/apache/pekko/stream/stage/GraphStage.scala Updates multiple null comparisons in graph stage logic
stream/src/main/scala/org/apache/pekko/stream/scaladsl/Hub.scala Updates null comparison in consumer management
stream/src/main/scala/org/apache/pekko/stream/scaladsl/Graph.scala Updates null comparisons in merge operations
stream/src/main/scala/org/apache/pekko/stream/javadsl/* Updates null comparisons in Java DSL classes
stream/src/main/scala/org/apache/pekko/stream/impl/* Updates null comparisons in stream implementation classes
serialization-jackson/src/main/scala/org/apache/pekko/serialization/jackson/JacksonSerializer.scala Updates null comparisons in serialization logic
remote/src/main/scala/org/apache/pekko/remote/* Updates null comparisons in remote transport and serialization
persistence/src/main/scala/org/apache/pekko/persistence/* Updates null comparisons in persistence logic
cluster*/src/main/scala/org/apache/pekko/cluster/* Updates null comparisons in cluster components
actor*/src/main/scala/org/apache/pekko/actor/* Updates null comparisons in actor system components

case Spawn(bhvr: Behavior[t], name, props, replyTo) =>
val ref =
if (name == null || name.equals(""))
if ((name eq null) || name.equals(""))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are the extra parentheses needed?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise for all the extra parentheses?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, otherwise compiling error

@mdedetrich mdedetrich left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good since we are only using ne/eq in null comparison checks which is the only safe case to use it.

Merge after you resolve @pjfanning 's comments regarding extra parens

This can also be backported to the 1.2.x series as its safe to do so (even 1.1.x if we are so inclined)

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@He-Pin
He-Pin merged commit 7325c72 into apache:main Aug 3, 2025
9 checks passed
@He-Pin
He-Pin deleted the eq branch August 3, 2025 09:32
@mdedetrich

Copy link
Copy Markdown
Contributor

@He-Pin Can you make backported/cherry picked commits for 1.2.x and 1.1.x?

@He-Pin

He-Pin commented Aug 3, 2025

Copy link
Copy Markdown
Member Author

yes, but not sure @pjfanning can agree

@pjfanning

Copy link
Copy Markdown
Member
  • 1.2.x is fine for backports
  • 1.1.x - I'm not quite so sure - it doesn't feel like a change that you would put in a patch release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants