Skip to content

Fix Java sampler export mutating profiling data - #588

Merged
lucko merged 1 commit into
lucko:masterfrom
tuxedomik:fix/java-sampler-export-mutation
Oct 4, 2026
Merged

lucko merged 1 commit into
lucko:masterfrom
tuxedomik:fix/java-sampler-export-mutation

Conversation

@tuxedomik

Copy link
Copy Markdown
Contributor

Summary

Fixes an issue where exporting Java sampler data could mutate the live profiling tree.

JavaNodeExporter merges stack trace nodes representing the same method before serializing them. Previously, this merge was performed directly on nodes from the sampler's live data:

other.merge(child);

Because toProto() can be called multiple times during a profiling session, such as by the live viewer and again when the profiler stops, repeated exports could progressively inflate descendant timings.

This could result in invalid profiles where child timings exceed their parents, percentages exceed 100%, and calculated self time becomes negative.

Fix

Use copy-on-write when merging nodes during export.

Nodes are reused normally. When a merge is required, the target node is first detached from the live sampler tree by copying it. The merge is then performed on that copy.

This avoids copying the entire profiling tree while ensuring serialization cannot modify the underlying sampling data.

Tests

Added a regression test which verifies that:

  • nodes representing the same method are still merged correctly in the exported profile
  • exporting the same sampler tree multiple times produces identical output
  • exporting does not modify the original sampler tree

./gradlew :spark-common:test passes.

Note

this was fixed by AI

@lucko
lucko merged commit 54a7034 into lucko:master Oct 4, 2026
@lucko

lucko commented Oct 4, 2026

Copy link
Copy Markdown
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants