Skip to content

Commit

Permalink
Use a LongAdder instead of an AtomicLong.
Browse files Browse the repository at this point in the history
Unlikely to matter, but technically has better performance under contention.

PiperOrigin-RevId: 680917850
Change-Id: I1a26f01d9e092427634f725bd2211c272500aecc
  • Loading branch information
tjgq authored and copybara-github committed Oct 1, 2024
1 parent 2d60e01 commit c72af54
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAdder;

/**
* A garbage collector for the disk cache.
Expand Down Expand Up @@ -235,8 +235,8 @@ private void visitDirectory(Path path) {

/** Deletes disk cache entries, performing I/O in parallel. */
private final class EntryDeleter extends AbstractQueueVisitor {
private final AtomicLong deletedEntries = new AtomicLong(0);
private final AtomicLong deletedBytes = new AtomicLong(0);
private final LongAdder deletedEntries = new LongAdder();
private final LongAdder deletedBytes = new LongAdder();

EntryDeleter() {
super(
Expand All @@ -252,8 +252,8 @@ void delete(Path path, long size) {
() -> {
try {
if (path.delete()) {
deletedEntries.incrementAndGet();
deletedBytes.addAndGet(size);
deletedEntries.increment();
deletedBytes.add(size);
}
} catch (IOException e) {
throw new IORuntimeException(e);
Expand All @@ -268,7 +268,7 @@ DeletionStats await() throws IOException, InterruptedException {
} catch (IORuntimeException e) {
throw e.getCauseIOException();
}
return new DeletionStats(deletedEntries.get(), deletedBytes.get());
return new DeletionStats(deletedEntries.sum(), deletedBytes.sum());
}
}
}

0 comments on commit c72af54

Please sign in to comment.