Skip to content

Conversation

@bogdandrutu
Copy link
Member

@bogdandrutu bogdandrutu commented Nov 26, 2025

This PR changes only the ottlspan.TransformContext, if gets approved will file separate PRs for all contexts.

  • In OTTL Expr and Getter/Setter the TransformContext is no longer pass as value avoiding a copy of 12 words (96B) every time an Expr/Getter/Setter of even simple Get* on the context itself funcs are called.
  • Avoid allocating a new pcommon.Map every time, very costly when is not needed.

This is breaking change for the API (not for final users), but one that is justified because of the latency and memory improvements. It is impossible (or almost impossible) to not break backwards compatibility unless duplicate a lot of code.

Comparing existing benchmarks:

Before:

BenchmarkTwoSpans
BenchmarkTwoSpans/no_processing
BenchmarkTwoSpans/no_processing-12         	  841123	      1327 ns/op	    2592 B/op	      46 allocs/op
BenchmarkTwoSpans/set_attribute
BenchmarkTwoSpans/set_attribute-12         	  743674	      1600 ns/op	    2640 B/op	      49 allocs/op
BenchmarkTwoSpans/keep_keys_attribute
BenchmarkTwoSpans/keep_keys_attribute-12   	  715513	      1685 ns/op	    2656 B/op	      50 allocs/op
BenchmarkTwoSpans/no_match
BenchmarkTwoSpans/no_match-12              	  702061	      1554 ns/op	    2624 B/op	      48 allocs/op
BenchmarkTwoSpans/inner_field
BenchmarkTwoSpans/inner_field-12           	  721738	      1621 ns/op	    2624 B/op	      48 allocs/op
BenchmarkTwoSpans/inner_field_both_spans
BenchmarkTwoSpans/inner_field_both_spans-12         	  716055	      1713 ns/op	    2656 B/op	      50 allocs/op

After:

BenchmarkTwoSpans
BenchmarkTwoSpans/no_processing
BenchmarkTwoSpans/no_processing-12         	 1000000	      1244 ns/op	    2337 B/op	      40 allocs/op
BenchmarkTwoSpans/set_attribute
BenchmarkTwoSpans/set_attribute-12         	  885855	      1369 ns/op	    2385 B/op	      43 allocs/op
BenchmarkTwoSpans/keep_keys_attribute
BenchmarkTwoSpans/keep_keys_attribute-12   	  812374	      1448 ns/op	    2401 B/op	      44 allocs/op
BenchmarkTwoSpans/no_match
BenchmarkTwoSpans/no_match-12              	  886906	      1331 ns/op	    2369 B/op	      42 allocs/op
BenchmarkTwoSpans/inner_field
BenchmarkTwoSpans/inner_field-12           	  871096	      1374 ns/op	    2369 B/op	      42 allocs/op
BenchmarkTwoSpans/inner_field_both_spans
BenchmarkTwoSpans/inner_field_both_spans-12         	  866323	      1417 ns/op	    2401 B/op	      44 allocs/op

Comparing benchmarks that do not need to allocate the data again every iteration and does not change the data to measure only the OTTL overhead:

Before:

BenchmarkSetName
BenchmarkSetName-12    	 9204532	       122.0 ns/op	      32 B/op	       2 allocs/op

After:

BenchmarkSetName
BenchmarkSetName-12    	 3745602	       305.7 ns/op	     288 B/op	       8 allocs/op

For the current performance benchmarks which are not allocating new TransformContext, here only benefit is because of the object copy part:

Before:

BenchmarkStatementSequenceExecuteSpans
BenchmarkStatementSequenceExecuteSpans/small
BenchmarkStatementSequenceExecuteSpans/small-12         	 1915495	       603.9 ns/op	     264 B/op	      16 allocs/op
BenchmarkStatementSequenceExecuteSpans/medium
BenchmarkStatementSequenceExecuteSpans/medium-12        	  279411	      4292 ns/op	    1464 B/op	      86 allocs/op
BenchmarkStatementSequenceExecuteSpans/large
BenchmarkStatementSequenceExecuteSpans/large-12         	   34627	     34848 ns/op	    6000 B/op	     350 allocs/op

After:

BenchmarkStatementSequenceExecuteSpans
BenchmarkStatementSequenceExecuteSpans/small
BenchmarkStatementSequenceExecuteSpans/small-12         	 1000000	      1004 ns/op	     264 B/op	      16 allocs/op
BenchmarkStatementSequenceExecuteSpans/medium
BenchmarkStatementSequenceExecuteSpans/medium-12        	  189889	      6194 ns/op	    1464 B/op	      86 allocs/op
BenchmarkStatementSequenceExecuteSpans/large
BenchmarkStatementSequenceExecuteSpans/large-12         	   29114	     39433 ns/op	    6000 B/op	     350 allocs/op

@bogdandrutu bogdandrutu force-pushed the use-pointer-for-context branch from 8216b9f to 8cf6645 Compare November 26, 2025 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants