Skip to content

Commit

Permalink
Move snapshot UUID generation at serialization
Browse files Browse the repository at this point in the history
UUID generation is not cheap, and therefore should be performed only
when the snapshot is about to be sent.
Moving UUID generation at serialization time makes it out of the
critical path.
  • Loading branch information
jpbempel committed Jul 5, 2024
1 parent 0327c4d commit 14cf31b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 0 additions & 1 deletion .gitlab/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ debugger-benchmarks:
- dd-java-agent/agent-debugger/**/*
compare_to: "master"
when: on_success
- when: manual
allow_failure: true
tags: ["runner:apm-k8s-tweaked-metal"]
interruptible: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class Snapshot {
private String exceptionId;

public Snapshot(java.lang.Thread thread, ProbeImplementation probeImplementation, int maxDepth) {
this.id = UUID.randomUUID().toString();
this.version = VERSION;
this.timestamp = System.currentTimeMillis();
this.captures = new Captures();
Expand Down Expand Up @@ -105,6 +104,10 @@ public void addCaughtExceptions(List<CapturedContext.CapturedThrowable> throwabl
}

public String getId() {
// lazily generates snapshot id
if (id == null) {
id = UUID.randomUUID().toString();
}
return id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public boolean offer(Snapshot snapshot) {
}

String serializeSnapshot(String serviceName, Snapshot snapshot) {
snapshot.getId(); // Ensure id is generated
String str = DebuggerAgent.getSnapshotSerializer().serializeSnapshot(serviceName, snapshot);
String prunedStr = SnapshotPruner.prune(str, MAX_SNAPSHOT_SIZE, 4);
if (prunedStr.length() != str.length()) {
Expand Down

0 comments on commit 14cf31b

Please sign in to comment.