mirror of https://github.com/grpc/grpc-java.git
core,grpclb: Resolve isAndroid only once on class loading (#10345)
Motivation: When multiple NameResolvers are created, the Classloader is scanned every time trying to figure out if the Platform is Android. This expensive work could be done only once. Modification: Cache isAndroid resolution in a constant. Result: Less expensive multiple NameResolvers instantiation.
This commit is contained in:
parent
0b53dd7304
commit
1e30cb6601
|
|
@ -46,6 +46,9 @@ public final class DnsNameResolverProvider extends NameResolverProvider {
|
|||
|
||||
private static final String SCHEME = "dns";
|
||||
|
||||
private static final boolean IS_ANDROID = InternalServiceProviders
|
||||
.isAndroid(DnsNameResolverProvider.class.getClassLoader());
|
||||
|
||||
@Override
|
||||
public NameResolver newNameResolver(URI targetUri, NameResolver.Args args) {
|
||||
if (SCHEME.equals(targetUri.getScheme())) {
|
||||
|
|
@ -60,7 +63,7 @@ public final class DnsNameResolverProvider extends NameResolverProvider {
|
|||
args,
|
||||
GrpcUtil.SHARED_CHANNEL_EXECUTOR,
|
||||
Stopwatch.createUnstarted(),
|
||||
InternalServiceProviders.isAndroid(getClass().getClassLoader())),
|
||||
IS_ANDROID),
|
||||
new BackoffPolicyRetryScheduler(
|
||||
new ExponentialBackoffPolicy.Provider(),
|
||||
args.getScheduledExecutorService(),
|
||||
|
|
|
|||
|
|
@ -53,6 +53,9 @@ final class SecretGrpclbNameResolverProvider {
|
|||
|
||||
private static final String SCHEME = "dns";
|
||||
|
||||
private static final boolean IS_ANDROID = InternalServiceProviders
|
||||
.isAndroid(SecretGrpclbNameResolverProvider.class.getClassLoader());
|
||||
|
||||
@Override
|
||||
public GrpclbNameResolver newNameResolver(URI targetUri, Args args) {
|
||||
if (SCHEME.equals(targetUri.getScheme())) {
|
||||
|
|
@ -68,7 +71,7 @@ final class SecretGrpclbNameResolverProvider {
|
|||
args,
|
||||
GrpcUtil.SHARED_CHANNEL_EXECUTOR,
|
||||
Stopwatch.createUnstarted(),
|
||||
InternalServiceProviders.isAndroid(getClass().getClassLoader()));
|
||||
IS_ANDROID);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue