Skip to content

Commit 441b1c6

Browse files
authored
Saving buildGitInfo lambda into a member variable (#10615)
* Saving buildGitInfo lambda into a member variable Unfortunately, profiles show the lambda from this:::buildGitIInfo being a hot allocation point. That would suggest that escape analysis wasn't able to kick in here. So I introduced a member variable to hold the variable to avoid repeatedly allocating * spotless
1 parent ba40c0e commit 441b1c6

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

internal-api/src/main/java/datadog/trace/api/git/GitInfoProvider.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public class GitInfoProvider {
4747
// in the same daemon is unlikely
4848
private final DDCache<String, GitInfo> gitInfoCache = DDCaches.newFixedSizeCache(4);
4949

50+
// DQH - The lambda in getGitInfo was a hot allocation point, so
51+
// pulled the lambda into a member variable to avoid constantly allocating.
52+
final Function<String, GitInfo> buildGitInfoFn = this::buildGitInfo;
53+
5054
public GitInfo getGitInfo() {
5155
return getGitInfo(null);
5256
}
@@ -56,7 +60,7 @@ public GitInfo getGitInfo(@Nullable String repositoryPath) {
5660
repositoryPath = NULL_PATH_STRING;
5761
}
5862

59-
return gitInfoCache.computeIfAbsent(repositoryPath, this::buildGitInfo);
63+
return gitInfoCache.computeIfAbsent(repositoryPath, buildGitInfoFn);
6064
}
6165

6266
private GitInfo buildGitInfo(String repositoryPath) {

0 commit comments

Comments
 (0)