Skip to content

Commit 82d8045

Browse files
authored
Optimize Git repository information computation (#8270)
* Moving null path computation into static Moving repeated null path computation into static variable. This change provides a 3% improvement on span creation benchmarks. * spotless
1 parent c527f13 commit 82d8045

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class GitInfoProvider {
2424
INSTANCE.registerGitInfoBuilder(new UserSuppliedGitInfoBuilder());
2525
}
2626

27+
static final String NULL_PATH_STRING = Paths.get("").toAbsolutePath().toString();
28+
2729
private volatile Collection<GitInfoBuilder> builders = Collections.emptyList();
2830

2931
// in regular cases git info has to be built only once,
@@ -42,7 +44,7 @@ public GitInfo getGitInfo() {
4244

4345
public GitInfo getGitInfo(@Nullable String repositoryPath) {
4446
if (repositoryPath == null) {
45-
repositoryPath = Paths.get("").toAbsolutePath().toString();
47+
repositoryPath = NULL_PATH_STRING;
4648
}
4749
return gitInfoCache.computeIfAbsent(repositoryPath, this::buildGitInfo);
4850
}

0 commit comments

Comments
 (0)