What would you like to be improved?
Follow-up to #1935. MultiProxyManager.getConfiguredProxy linearly scans the configured proxies on every metadata-override request, to reuse the configured SCProxy instance for usage accounting. O(n) per override request.
Low priority. A miss is harmless (the metadata proxy is still used, just as a throwaway instance), the override path is opt-in per URL, and getLeastUsed already does a comparable per-request scan. This is cleanup, not a measured bottleneck. To be clear, getLeastUsed is inherently O(n) and is not a target here; I mention it only because O(n) is already accepted on this path.
How should we improve?
The lookup only exists to reuse the configured SCProxy so its usage counter keeps incrementing. The cleanest fix puts proxy identity on the type instead of rebuilding it in a separate key.
- Give
SCProxy an equals/hashCode based on its identity fields only: protocol and address lowercased, plus port, username and password. Leave out country, area, location, status and usage. None of the identity fields have setters, so the hash stays stable for the life of the object. (A blind "generate equals/hashCode" from the IDE pulls in every field, which is wrong here.)
- Build a
Map<SCProxy, SCProxy> in both configure() methods and turn getConfiguredProxy into Optional.ofNullable(map.get(proxy)), which makes it O(1).
ProxyUtils.isSameProxy is only called by getConfiguredProxy, so after step 2 it has no callers. Fold its logic into SCProxy.equals and delete isSameProxy along with its private normalize helper. Keep ProxyUtils itself, since it still holds validatePortRange. A normalized string key would also work, but it duplicates the same five-field comparison and leaves two definitions of proxy identity to keep in sync.
No behavior change. This is a code-quality cleanup (single identity definition, less dead code), not a performance fix.
What would you like to be improved?
Follow-up to #1935.
MultiProxyManager.getConfiguredProxylinearly scans the configured proxies on every metadata-override request, to reuse the configuredSCProxyinstance for usage accounting. O(n) per override request.Low priority. A miss is harmless (the metadata proxy is still used, just as a throwaway instance), the override path is opt-in per URL, and
getLeastUsedalready does a comparable per-request scan. This is cleanup, not a measured bottleneck. To be clear,getLeastUsedis inherently O(n) and is not a target here; I mention it only because O(n) is already accepted on this path.How should we improve?
The lookup only exists to reuse the configured
SCProxyso its usage counter keeps incrementing. The cleanest fix puts proxy identity on the type instead of rebuilding it in a separate key.SCProxyanequals/hashCodebased on its identity fields only: protocol and address lowercased, plus port, username and password. Leave outcountry,area,location,statusandusage. None of the identity fields have setters, so the hash stays stable for the life of the object. (A blind "generate equals/hashCode" from the IDE pulls in every field, which is wrong here.)Map<SCProxy, SCProxy>in bothconfigure()methods and turngetConfiguredProxyintoOptional.ofNullable(map.get(proxy)), which makes it O(1).ProxyUtils.isSameProxyis only called bygetConfiguredProxy, so after step 2 it has no callers. Fold its logic intoSCProxy.equalsand deleteisSameProxyalong with its privatenormalizehelper. KeepProxyUtilsitself, since it still holdsvalidatePortRange. A normalized string key would also work, but it duplicates the same five-field comparison and leaves two definitions of proxy identity to keep in sync.No behavior change. This is a code-quality cleanup (single identity definition, less dead code), not a performance fix.