Keep baggage sample rate/rand as doubles#4279
Conversation
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 2bb10ef | 439.64 ms | 446.10 ms | 6.46 ms |
| e9d765b | 375.22 ms | 445.06 ms | 69.84 ms |
| f2b6704 | 406.86 ms | 435.69 ms | 28.83 ms |
| 902043e | 409.27 ms | 486.46 ms | 77.19 ms |
| 524a008 | 464.70 ms | 594.53 ms | 129.84 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 2bb10ef | 1.58 MiB | 2.22 MiB | 652.83 KiB |
| e9d765b | 1.58 MiB | 2.22 MiB | 652.62 KiB |
| f2b6704 | 1.58 MiB | 2.22 MiB | 652.55 KiB |
| 902043e | 1.58 MiB | 2.22 MiB | 652.54 KiB |
| 524a008 | 1.58 MiB | 2.22 MiB | 652.84 KiB |
| @@ -231,8 +261,18 @@ public String getThirdPartyHeader() { | |||
| } | |||
|
|
|||
| final Set<String> keys = new TreeSet<>(keyValues.keySet()); | |||
There was a problem hiding this comment.
I know this is quite hacky, an alternative would be to let keyValues be a Map<String, String|Number> aka Map<String, Object>
There was a problem hiding this comment.
We can revisit when more fields need to be added in the future and this current approach gets harder to maintain. I think it's fine for now.
|
|
||
| @ApiStatus.Internal | ||
| @Override | ||
| public @NotNull PropagationContext withPropagationContext( |
There was a problem hiding this comment.
What's the use case of returning a clone of PropagationContext here? As far as I can see we at least internally never seem to use the return type.
There was a problem hiding this comment.
To avoid modifications from outside the withPropagationContext block, i.e. misusing this as a getter for modifying the instance.
| @@ -231,8 +261,18 @@ public String getThirdPartyHeader() { | |||
| } | |||
|
|
|||
| final Set<String> keys = new TreeSet<>(keyValues.keySet()); | |||
There was a problem hiding this comment.
We can revisit when more fields need to be added in the future and this current approach gets harder to maintain. I think it's fine for now.
|
|
||
| @ApiStatus.Internal | ||
| @Override | ||
| public @NotNull PropagationContext withPropagationContext( |
There was a problem hiding this comment.
To avoid modifications from outside the withPropagationContext block, i.e. misusing this as a getter for modifying the instance.
| private @NotNull List<Attachment> attachments = new CopyOnWriteArrayList<>(); | ||
|
|
||
| private @NotNull PropagationContext propagationContext; | ||
| private @NotNull LazyEvaluator<PropagationContext> propagationContext; |
There was a problem hiding this comment.
Did we do any performance comparison as to whether this specific part actually improves anything?
There was a problem hiding this comment.
No I didn't, and after sleeping over it I think it's better to revert this specific change: it makes everything less predictable 😅 I'll do a quick test, but I suspect the performance gains to be negligible.
There was a problem hiding this comment.
Ok I did some testing using https://github.com/melix/jmh-gradle-plugin/, it's all within the same ballpark.
This is throughput, so higher values are better.
# Without Lazy
Benchmark Mode Cnt Score Error Units
ScopeBenchmark.ctor thrpt 4 4063093,683 ± 185929,301 ops/s
ScopeBenchmark.getPropagationContext thrpt 4 4283007,711 ± 1670048,430 ops/s
# With Lazy
Benchmark Mode Cnt Score Error Units
ScopeBenchmark.ctor thrpt 4 4639302,930 ± 518388,199 ops/s
ScopeBenchmark.getPropagationContext thrpt 4 3769735,655 ± 102168,937 ops/s
There was a problem hiding this comment.
Which ctor did you test there? The Scope(final @NotNull Scope scope) one or the Scope(final @NotNull SentryOptions options) one?
Scope(final @NotNull SentryOptions options)should only be used oninitScope(final @NotNull Scope scope)is used byclonevery often
There was a problem hiding this comment.
In general I'd say, if this has little to no benefit, let's rather keep it simple and avoid LazyEvaluator here.
There was a problem hiding this comment.
I did test Scope(final @NotNull SentryOptions options) so the one being used for init. Here's the code I used for testing. But yeah let's keep it without lazy, the ctor gain is just too small.
Co-authored-by: Alexander Dinauer <adinauer@users.noreply.github.com>
This reverts commit 398c5df.
📜 Description
Keeps the rate / rand values as doubles, until being transferred to
TraceContext.💡 Motivation and Context
We seem to be hitting some performance regression with 8.x.x where formatting the sample rate/rand seems to have some impact. I don't trust the profiled app fully, be there seems to be something to it:
Before:

After:

TODO: Check why this even being called 3 times (assuming it's for every scope right now)
💚 How did you test it?
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps