dubbo-go icon indicating copy to clipboard operation
dubbo-go copied to clipboard

perf(loadbalance): reduce per-select temporary slice allocations

Open Alanxtl opened this issue 5 months ago • 2 comments

Background

Some load balance implementations allocate temporary slices on each Select call. For common small invoker lists, those allocations can be avoided without changing the selection algorithm.

Examples include weighted random, least-active selection, and alias-method picker construction.

Scope

Reduce temporary allocations in request-time load balance selection while keeping the existing selection semantics unchanged. A conservative approach is to use fixed-size stack arrays for small invoker counts and fall back to heap slices for larger lists.

Relevant code:

  • cluster/loadbalance/random/loadbalance.go
  • cluster/loadbalance/leastactive/loadbalance.go
  • cluster/loadbalance/aliasmethod/alias_method.go

Acceptance Criteria

  • Load balance behavior and existing tests remain unchanged.
  • Benchmarks show reduced allocations for representative small and medium invoker counts.
  • Avoid introducing long-lived caches in this issue; keep the change local and low-risk.
  • go test ./cluster/loadbalance passes.

Alanxtl avatar Jun 13 '26 06:06 Alanxtl

Please assign to me

Vanillaxi avatar Jun 13 '26 06:06 Vanillaxi

close via #3415

Alanxtl avatar Jun 14 '26 07:06 Alanxtl