linkedin / rest.li

Rest.li is a REST+JSON framework for building robust, scalable service architectures using dynamic discovery and simple asynchronous APIs.
rest.li
Other
2.51k stars 546 forks source link

[rest.li] Update SimpleLoadBalancer to use for loop instead of Map #947

Closed vshwnth2 closed 11 months ago

vshwnth2 commented 11 months ago

[rest.li] Update SimpleLoadBalancer to use for loop instead of Map

When running ODP analysis, we observed that SimpleLoadBalancer.getPotentialClients map collect uses around 4% CPU. Much of this seems Collector.toMap's uniqKeysMapAccumulator. In this scenario, this is performing unnecessary extra computation -- the keys of the Map we are creating come directly from a Set.

The updated implementation avoids the stream(...).collect(Collectors.toMap(...) and directly uses a for loop to populate the Map

252851489-1cc65047-d39b-4f34-888f-b98e5f000d03