Skip to content

Commit

Permalink
fix unused import, apply to PercentileDistributionSummary
Browse files Browse the repository at this point in the history
  • Loading branch information
brharrington committed Mar 22, 2024
1 parent 143814a commit 69084b7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ subprojects {
profilers = ['stack', 'gc']
includeTests = false
duplicateClassesStrategy = DuplicatesStrategy.WARN
includes = ['.*Caching.*']
includes = ['.*PercentileTimers.*']
}

checkstyle {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 Netflix, Inc.
* Copyright 2014-2024 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,7 +22,6 @@
import com.netflix.spectator.api.Measurement;
import com.netflix.spectator.api.Registry;
import com.netflix.spectator.api.Statistic;
import com.netflix.spectator.api.Utils;
import com.netflix.spectator.api.patterns.IdBuilder;
import com.netflix.spectator.api.patterns.TagsBuilder;

Expand Down Expand Up @@ -66,8 +65,20 @@ public final class PercentileDistributionSummary implements DistributionSummary
*/
private static PercentileDistributionSummary computeIfAbsent(
Registry registry, Id id, long min, long max) {
Object summary = Utils.computeIfAbsent(
registry.state(), id, i -> new PercentileDistributionSummary(registry, id, min, max));
// Inlined:
// Object summary = Utils.computeIfAbsent(
// registry.state(), id, i -> new PercentileDistributionSummary(registry, id, min, max));
//
// The lambda needs to capture the parameters for registry, min, and max which can lead to
// a high allocation rate for the lambda instance.
Object summary = registry.state().get(id);
if (summary == null) {
PercentileDistributionSummary newSummary = new PercentileDistributionSummary(registry, id, min, max);
summary = registry.state().putIfAbsent(id, newSummary);
if (summary == null) {
return newSummary;
}
}
return (summary instanceof PercentileDistributionSummary)
? ((PercentileDistributionSummary) summary).withRange(min, max)
: new PercentileDistributionSummary(registry, id, min, max);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2023 Netflix, Inc.
* Copyright 2014-2024 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,6 @@
import com.netflix.spectator.api.Registry;
import com.netflix.spectator.api.Statistic;
import com.netflix.spectator.api.Timer;
import com.netflix.spectator.api.Utils;
import com.netflix.spectator.api.patterns.IdBuilder;
import com.netflix.spectator.api.patterns.TagsBuilder;

Expand Down Expand Up @@ -72,6 +71,12 @@ public final class PercentileTimer implements Timer {
* site.
*/
private static PercentileTimer computeIfAbsent(Registry registry, Id id, long min, long max) {
// Inlined:
// Object timer = Utils.computeIfAbsent(
// registry.state(), id, i -> new PercentileTimer(registry, id, min, max));
//
// The lambda needs to capture the parameters for registry, min, and max which can lead to
// a high allocation rate for the lambda instance.
Object timer = registry.state().get(id);
if (timer == null) {
PercentileTimer newTimer = new PercentileTimer(registry, id, min, max);
Expand Down

0 comments on commit 69084b7

Please sign in to comment.