Skip to content

Fix collection performance anti-patterns and ChannelContext logic bugs#1535

Open
Copilot wants to merge 3 commits intomasterfrom
copilot/check-performance-logic-issues
Open

Fix collection performance anti-patterns and ChannelContext logic bugs#1535
Copilot wants to merge 3 commits intomasterfrom
copilot/check-performance-logic-issues

Conversation

Copy link
Contributor

Copilot AI commented Mar 3, 2026

Audit of core modules for performance and correctness issues.

Performance fixes

  • size() == 0isEmpty() across 6 files — isEmpty() is O(1) for all collections; size() is O(n) for ConcurrentLinkedQueue (used in BatchExecutorQueue)
  • Remove redundant Collections.synchronizedMap(new ConcurrentHashMap<>()) in RouterChain — double-wrapping negates ConcurrentHashMap's striped locking with a single coarse mutex
  • Eliminate containsKey() + get() double-lookup in ChannelContext.invalidateHeadCache() — single get() with null check

Logic bug fix

  • ChannelContext.invalidateHeadCache(Byte key, ...)Short key — the backing TwoWayMap<Short, String> uses Short keys, so Byte lookups via Map.get(Object) never matched, making the method silently no-op:
// Before: Byte ≠ Short, containsKey/get always returns false/null
public void invalidateHeadCache(Byte key, String value) { ... }

// After: types align with TwoWayMap<Short, String>
public void invalidateHeadCache(Short key, String value) { ... }

Tests

  • Added ChannelContextTest (12 cases) covering cache put/get, invalidation (success, mismatch, missing key, null cache), ref index allocation, and property accessors. Previously had zero coverage.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • repository.jboss.org
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java -classpath /home/REDACTED/work/sofa-rpc/sofa-rpc/.mvn/wrapper/maven-wrapper.jar -Dmaven.home=/home/REDACTED/work/sofa-rpc -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/sofa-rpc/sofa-rpc org.apache.maven.wrapper.MavenWrapperMain -f pom.xml -B -V -e -Dfindbugs.skip -Dcheckstyle.skip -Dpmd.skip=true -Dspotbugs.skip -Denforcer.skip -Dmaven.javadoc.skip -DskipTests -Dmaven.test.skip.exec -Dlicense.skip=true (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits March 3, 2026 07:22
…ndant synchronizedMap wrapping, eliminate double map lookup, add ChannelContext tests

Co-authored-by: sunhailin-Leo <17564655+sunhailin-Leo@users.noreply.github.com>
…update tests

Co-authored-by: sunhailin-Leo <17564655+sunhailin-Leo@users.noreply.github.com>
Copilot AI changed the title [WIP] Identify and fix performance or logic issues Fix collection performance anti-patterns and ChannelContext logic bugs Mar 3, 2026
@sunhailin-Leo sunhailin-Leo requested review from EvenLjj and Copilot March 4, 2026 06:57
Copy link

Copilot AI left a comment

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 audits several core modules to fix collection performance anti-patterns and a logic bug in ChannelContext.

Changes:

  • isEmpty() replacements: Replaces size() == 0 with isEmpty() across 6 files (AbstractHttpServer, LocalRegistry, BatchExecutorQueue, RpcConfigs, BeanIdMatchFilter, AbstractLoadBalancer) for idiomatic and potentially more performant checks.
  • RouterChain simplification: Removes the redundant Collections.synchronizedMap() wrapper around ConcurrentHashMap for PROVIDER_AUTO_ACTIVES and CONSUMER_AUTO_ACTIVES (safe since iterations over these maps are followed by a sort-by-order step).
  • ChannelContext bug fix: Corrects invalidateHeadCache's parameter type from Byte to Short (matching the TwoWayMap<Short, String> backing), eliminates the containsKey + get double-lookup, and adds a new ChannelContextTest covering 12 cases.

Reviewed changes

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

Show a summary per file
File Description
AbstractHttpServer.java size() == 0isEmpty() in unRegisterProcessor
LocalRegistry.java size() == 0isEmpty() in unSubscribe
BatchExecutorQueue.java size() == 0isEmpty() on snapshot (a LinkedList) in run()
RpcConfigs.java size() == 0isEmpty() in unSubscribe
RouterChain.java Removes Collections.synchronizedMap() double-wrapping around ConcurrentHashMap
BeanIdMatchFilter.java size() == 0isEmpty() in isMatch
AbstractLoadBalancer.java size() == 0isEmpty() in select
ChannelContext.java Fixes invalidateHeadCache parameter type ByteShort and eliminates containsKey+get double-lookup
ChannelContextTest.java New 12-case unit test class covering cache operations and ChannelContext accessors

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sunhailin-Leo sunhailin-Leo marked this pull request as ready for review March 4, 2026 07:03
@EvenLjj EvenLjj added this to the 5.14.2 milestone Mar 6, 2026
@EvenLjj EvenLjj requested a review from Copilot March 6, 2026 09:42
@sunhailin-Leo sunhailin-Leo removed this from the 5.14.2 milestone Mar 6, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

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