Disable file uploader codepaths when disabled. Previously we would run through the surprisingly expensive codepath and bail out only at the very end: an expensive no-op.

RELNOTES: None
PiperOrigin-RevId: 243818746
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceUploader.java b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceUploader.java
index c69ff9a..9a541ae 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceUploader.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceUploader.java
@@ -24,7 +24,6 @@
 import com.google.common.base.Preconditions;
 import com.google.common.base.Throwables;
 import com.google.common.collect.Iterables;
-import com.google.common.collect.Maps;
 import com.google.common.eventbus.EventBus;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
@@ -43,7 +42,6 @@
 import com.google.devtools.build.lib.buildeventstream.ArtifactGroupNamer;
 import com.google.devtools.build.lib.buildeventstream.BuildCompletingEvent;
 import com.google.devtools.build.lib.buildeventstream.BuildEvent;
-import com.google.devtools.build.lib.buildeventstream.BuildEvent.LocalFile;
 import com.google.devtools.build.lib.buildeventstream.BuildEventArtifactUploader;
 import com.google.devtools.build.lib.buildeventstream.BuildEventContext;
 import com.google.devtools.build.lib.buildeventstream.BuildEventProtocolOptions;
@@ -56,7 +54,6 @@
 import com.google.devtools.build.lib.util.ExitCode;
 import com.google.devtools.build.lib.util.LoggingUtil;
 import com.google.devtools.build.lib.util.Sleeper;
-import com.google.devtools.build.lib.vfs.Path;
 import com.google.devtools.build.v1.BuildStatus.Result;
 import com.google.devtools.build.v1.PublishBuildToolEventStreamRequest;
 import com.google.devtools.build.v1.PublishLifecycleEventRequest;
@@ -67,10 +64,9 @@
 import io.grpc.Status.Code;
 import io.grpc.StatusException;
 import java.time.Duration;
-import java.util.Collection;
-import java.util.Map;
+import java.util.ArrayDeque;
+import java.util.Deque;
 import java.util.concurrent.BlockingDeque;
-import java.util.concurrent.ConcurrentLinkedDeque;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.LinkedBlockingDeque;
 import java.util.concurrent.TimeUnit;
@@ -187,7 +183,7 @@
     // This needs to happen outside a synchronized block as it may trigger
     // stdout/stderr and lead to a deadlock. See b/109725432
     ListenableFuture<PathConverter> localFileUploadFuture =
-        uploadReferencedLocalFiles(event.referencedLocalFiles());
+        localFileUploader.uploadReferencedLocalFiles(event.referencedLocalFiles());
 
     synchronized (lock) {
       if (closeFuture != null) {
@@ -392,7 +388,7 @@
     // Every build event sent to the server needs to be acknowledged by it. This queue stores
     // the build events that have been sent and still have to be acknowledged by the server.
     // The build events are stored in the order they were sent.
-    ConcurrentLinkedDeque<SendBuildEventCommand> ackQueue = new ConcurrentLinkedDeque<>();
+    Deque<SendBuildEventCommand> ackQueue = new ArrayDeque<>();
     boolean lastEventSent = false;
     int acksReceived = 0;
     int retryAttempt = 0;
@@ -481,7 +477,7 @@
                           expected.getSequenceNumber(), actualSeqNum);
                   logger.info(message);
                   streamContext.abortStream(Status.FAILED_PRECONDITION.withDescription(message));
-              }
+                }
               } else {
                 String message =
                     String.format(
@@ -625,18 +621,6 @@
     throw cause;
   }
 
-  private ListenableFuture<PathConverter> uploadReferencedLocalFiles(
-      Collection<LocalFile> localFiles) {
-    Map<Path, LocalFile> localFileMap = Maps.newHashMapWithExpectedSize(localFiles.size());
-    for (LocalFile localFile : localFiles) {
-      // It is possible for targets to have duplicate artifacts (same path but different owners)
-      // in their output groups. Since they didn't trigger an artifact conflict they are the
-      // same file, so just skip either one
-      localFileMap.putIfAbsent(localFile.path, localFile);
-    }
-    return localFileUploader.upload(localFileMap);
-  }
-
   private void ensureUploadThreadStarted() {
     synchronized (lock) {
       if (uploadThread == null) {