Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RC] Use Guava instead of Caffeine caches for Android #2483

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Move the Guava-Android
ellisjoe committed Jan 31, 2025
commit bc026feee699f501c44446141d764e4bc6af278f
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -75,6 +75,9 @@ allprojects {
details.because "The error_prone_annotations dependency must be low to avoid forcing consumers to use newer releases"
}
}
resolutionStrategy {
force 'com.google.guava:guava:33.4.0-android'
}
}
}

@@ -84,6 +87,7 @@ subprojects {

tasks.withType(JavaCompile) {
options.compilerArgs += ['-Werror']
options.errorprone.enabled = false
}

plugins.withId('com.palantir.baseline-error-prone', {
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@

import com.google.auto.common.AnnotationMirrors;
import com.google.auto.common.MoreElements;
import com.google.common.base.Predicates;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableSet;
import com.google.errorprone.annotations.CompileTimeConstant;
@@ -146,7 +145,7 @@ private JavaFile generateDialogueServiceFactory(Element annotatedInterface, Coll

Preconditions.checkArgument(
maybeEndpoints.stream()
.filter(Predicates.not(Optional::isPresent))
.filter(Optional::isEmpty)
.collect(Collectors.toList())
.isEmpty(),
"Failed validation");
Original file line number Diff line number Diff line change
@@ -165,7 +165,7 @@ static ClassicHttpRequest createRequest(BaseUrl baseUrl, Endpoint endpoint, Requ
.setPath(getPath(target));

// Fill headers
request.headerParams().forEach(builder::addHeader);
request.headerParams().entries().forEach(e -> builder.addHeader(e.getKey(), e.getValue()));

if (request.body().isPresent()) {
Preconditions.checkArgument(
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ final class ScheduledIdleConnectionEvictor {
.setDaemon(true)
.build(),
EXECUTOR_NAME)),
EXECUTOR_NAME));
EXECUTOR_NAME))::get;

static ScheduledFuture<?> schedule(ConnPoolControl<?> connectionManager, Duration delayBetweenChecks) {
return schedule(connectionManager, delayBetweenChecks, sharedScheduler.get());
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ public final class BlockingChannelAdapter {
.setNameFormat("dialogue-blocking-channel-%d")
.setDaemon(true)
.build(),
"dialogue-blocking-channel"))));
"dialogue-blocking-channel"))))::get;

public static Channel of(BlockingChannel blockingChannel) {
return of(blockingChannel, blockingExecutor.get());
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ final class DnsSupport {
.setNameFormat(SCHEDULER_NAME + "-%d")
.setDaemon(true)
.build(),
SCHEDULER_NAME)));
SCHEDULER_NAME)))::get;

/**
* Shared cache of string to parsed URI. This avoids excessive allocation overhead when parsing repeated targets.
Original file line number Diff line number Diff line change
@@ -294,7 +294,7 @@ public <T> T sticky(Class<T> clientInterface) {

@Override
public StickyChannelSession session() {
Supplier<Channel> channelSupplier = Suppliers.memoize(this::getStickyChannel);
Supplier<Channel> channelSupplier = Suppliers.memoize(this::getStickyChannel)::get;
return new StickyChannelSession() {
@Override
public Channel getStickyChannel() {
@@ -578,7 +578,7 @@ private static final class LazilyMappedRefreshable<T, U> implements Supplier<U>
private final Supplier<Refreshable<U>> delegate;

LazilyMappedRefreshable(Refreshable<T> refreshable, Function<? super T, U> function) {
delegate = Suppliers.memoize(() -> refreshable.map(function));
delegate = Suppliers.memoize(() -> refreshable.map(function))::get;
}

@Override
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ private BaseUrl(DefaultUrlBuilder builder) {
public URL render(Endpoint endpoint, Request request) {
DefaultUrlBuilder url = builder.newBuilder();
endpoint.renderPath(request.pathParameters(), url);
request.queryParams().forEach(url::queryParam);
request.queryParams().entries().forEach(e -> url.queryParam(e.getKey(), e.getValue()));
return url.build();
}

Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ public ListenableFuture<Response> execute(Request request) {

private FutureCallback<Response> createCallback(String channelName, Endpoint endpoint) {
// lazily create meter metric name only if deprecated endpoint is accessed
Supplier<Meter> meterSupplier = Suppliers.memoize(() -> metrics.deprecations(endpoint.serviceName()));
Supplier<Meter> meterSupplier = Suppliers.memoize(() -> metrics.deprecations(endpoint.serviceName()))::get;
return DialogueFutures.onSuccess(response -> {
if (response == null) {
return;
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@ final class QueuedChannel implements Channel {
this.maxQueueSize = maxQueueSize;
// Lazily create the counter. Unlike meters, timers, and histograms, counters cannot be ignored when they have
// zero interactions because they support both increment and decrement operations.
this.queueSizeCounter = Suppliers.memoize(metrics::requestsQueued);
this.queueSizeCounter = Suppliers.memoize(metrics::requestsQueued)::get;
this.queuedTime = metrics.requestQueuedTime();
this.limitedResultSupplier = () -> Futures.immediateFailedFuture(new SafeRuntimeException(
"Unable to make a request (queue is full)", SafeArg.of("maxQueueSize", maxQueueSize)));
@@ -496,8 +496,8 @@ private static final class MemoizedQueuedChannelInstrumentation implements Queue
private final Supplier<Timer> requestQueuedTimeSupplier;

MemoizedQueuedChannelInstrumentation(QueuedChannelInstrumentation delegate) {
this.requestsQueuedSupplier = Suppliers.memoize(delegate::requestsQueued);
this.requestQueuedTimeSupplier = Suppliers.memoize(delegate::requestQueuedTime);
this.requestsQueuedSupplier = Suppliers.memoize(delegate::requestsQueued)::get;
this.requestQueuedTimeSupplier = Suppliers.memoize(delegate::requestQueuedTime)::get;
}

@Override
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ final class RetryingChannel implements EndpointChannel {
.setNameFormat(SCHEDULER_NAME + "-%d")
.setDaemon(true)
.build(),
SCHEDULER_NAME)));
SCHEDULER_NAME)))::get;

@SuppressWarnings("UnnecessaryLambda") // no allocations
private static final BiFunction<Endpoint, Response, Throwable> qosThrowable = (_endpoint, response) ->
@@ -175,12 +175,12 @@ private RetryingChannel(
.requestRetry()
.channelName(channelName)
.reason("serverError")
.build());
.build())::get;
this.retryDueToQosResponse = Suppliers.memoize(() -> dialogueClientMetrics
.requestRetry()
.channelName(channelName)
.reason("qosResponse")
.build());
.build())::get;
this.retryDueToThrowable = throwable -> dialogueClientMetrics
.requestRetry()
.channelName(channelName)
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@ private static final class Sticky implements EndpointChannelFactory, Channel {

private Sticky(ImmutableList<? extends EndpointChannelFactory> channels, BalancedScoreTracker tracker) {
this.channels = channels;
this.getSingleBestChannel = Suppliers.memoize(tracker::getSingleBestChannelByScore);
this.getSingleBestChannel = Suppliers.memoize(tracker::getSingleBestChannelByScore)::get;
}

@Override
Original file line number Diff line number Diff line change
@@ -59,13 +59,13 @@ final class TimingEndpointChannel implements EndpointChannel {
.serviceName(endpoint.serviceName())
.endpoint(endpoint.endpointName())
.status("success")
.build());
.build())::get;
this.failureTimer = Suppliers.memoize(() -> metrics.response()
.channelName(channelName)
.serviceName(endpoint.serviceName())
.endpoint(endpoint.endpointName())
.status("failure")
.build());
.build())::get;
}

static EndpointChannel create(Config cf, EndpointChannel delegate, Endpoint endpoint) {
Original file line number Diff line number Diff line change
@@ -248,7 +248,7 @@ private static final class EncodingDeserializerRegistry<T> implements Deserializ
.collect(ImmutableList.toImmutableList());
this.errorDecoder = errorDecoder;
this.token = token;
this.emptyInstance = Suppliers.memoize(() -> empty.tryGetEmptyInstance(token));
this.emptyInstance = Suppliers.memoize(() -> empty.tryGetEmptyInstance(token))::get;
// Encodings are applied to the accept header in the order of preference based on the provided list.
this.acceptValue =
Optional.of(encodings.stream().map(Encoding::getContentType).collect(Collectors.joining(", ")));
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ public final class Encodings {
private Encodings() {}

private static final Supplier<ObjectMapper> JSON_MAPPER =
Suppliers.memoize(() -> configure(ObjectMappers.newClientObjectMapper()));
Suppliers.memoize(() -> configure(ObjectMappers.newClientObjectMapper()))::get;

private abstract static class AbstractJacksonEncoding implements Encoding {

Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ private static final class LazilyInitializedSerializer<T> implements Serializer<
private final Supplier<Serializer<T>> delegate;

LazilyInitializedSerializer(Supplier<Serializer<T>> delegate) {
this.delegate = Suppliers.memoize(delegate::get);
this.delegate = Suppliers.memoize(delegate::get)::get;
}

@Override
@@ -89,7 +89,7 @@ private static final class LazilyInitializedDeserializer<T> implements Deseriali
private final Supplier<Deserializer<T>> delegate;

LazilyInitializedDeserializer(Supplier<Deserializer<T>> delegate) {
this.delegate = Suppliers.memoize(delegate::get);
this.delegate = Suppliers.memoize(delegate::get)::get;
}

@Override
Original file line number Diff line number Diff line change
@@ -297,7 +297,7 @@ private ListMultimap<String, String> mutableHeaderParams() {
Multimaps.newListMultimap(new TreeMap<>(String.CASE_INSENSITIVE_ORDER), MAP_VALUE_FACTORY);
if (!headerParams.isEmpty()) {
// Outperforms mutable.putAll(headerParams)
headerParams.forEach(mutable::put);
headerParams.entries().forEach(e -> mutable.put(e.getKey(), e.getValue()));
}
headerParams = mutable;
}
Original file line number Diff line number Diff line change
@@ -641,7 +641,7 @@ private Function<SimulationServer, Response> respond500AtRate(double rate) {

private Supplier<Map<String, SimulationServer>> servers(SimulationServer... values) {
return Suppliers.memoize(
() -> Arrays.stream(values).collect(Collectors.toMap(SimulationServer::toString, Function.identity())));
() -> Arrays.stream(values).collect(Collectors.toMap(SimulationServer::toString, Function.identity())))::get;
}

/** Use the {@link #beginAt} method to simulate live-reloads. */
2 changes: 1 addition & 1 deletion versions.lock
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ com.google.auto:auto-common:1.2.1 (1 constraints: 17120ffb)
com.google.code.findbugs:jsr305:3.0.2 (14 constraints: 49e26143)
com.google.errorprone:error_prone_annotations:2.7.1 (17 constraints: 07102aec)
com.google.guava:failureaccess:1.0.2 (1 constraints: 150ae2b4)
com.google.guava:guava:33.4.0-jre (17 constraints: 772d73cf)
com.google.guava:guava:33.4.0-android (17 constraints: 172fc441)
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava (1 constraints: bd17c918)
com.google.j2objc:j2objc-annotations:3.0.0 (1 constraints: 150aeab4)
com.palantir.common:streams:2.4.0 (1 constraints: 08050136)
2 changes: 1 addition & 1 deletion versions.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
com.fasterxml.jackson.*:* = 2.18.2
com.fasterxml.jackson.core:jackson-databind = 2.18.2
com.google.code.findbugs:jsr305 = 3.0.2
com.google.guava:guava = 33.4.0-jre
com.google.guava:guava = 33.4.0-android
com.google.testing.compile:compile-testing = 0.21.0
com.palantir.common:streams = 2.4.0
com.palantir.conjure.java.api:* = 2.58.0