Skip to content

Avoid allocations in ChannelPoolPartioning #2157

Description

@doom369
Image

Currently, ChannelPoolPartitioning does allocation for every request in uri.getBaseUrl();. The simplest possible fix is to replace uri.getBaseUrl() with uri.getHost() or maybe with the URI itself.

@hyperxpro WDYT?

Activity

  1. hyperxpro commented on Apr 1, 2026

    @hyperxpro
    Member

    Great find.

    However, using uri.getHost() will only return the hostname, not the port and schema. How about using a record class, something like this:

    record PartitionKey(String scheme, String host, int port) {}
      @Override                                                                                                                                                                                                                                                                                                                                                                                                                                
      public Object getPartitionKey(Uri uri, @Nullable String virtualHost, @Nullable ProxyServer proxyServer) {
          if (proxyServer == null && virtualHost == null) {                                                                                                                                                                                                                                                                                                                                                                                    
              return new PartitionKey(uri.getScheme(), uri.getHost(), uri.getExplicitPort());
          }                                                                                                                                                                                                                                                                                                                                                                                                                                    
          // rest of the code...
      } 

    This will avoid String allocation, and comparisons will be faster too.

  2. doom369 commented on Apr 2, 2026

    @doom369
    ContributorAuthor

    @hyperxpro works for me. do you want me to send PR or you'll do it?

  3. hyperxpro commented on Apr 2, 2026

    @hyperxpro
    Member

    Send a PR please :)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions