perf(core): [SDK Overhead Reduction 10] Lazily create reflection JSON serializer#5601
Conversation
Defer creation of JsonReflectionObjectSerializer until unknown-object reflection serialization is needed. Normal SDK payloads use explicit serializers, so this avoids allocating unused reflection serializer state for each writer.
📲 Install BuildsAndroid
|
|
Cursor review |
|
@sentry review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit fd46dbe. Configure here.
Performance metrics 🚀
|
…o perf/sdk-overhead-reduction-reflection-serializer # Conflicts: # CHANGELOG.md
runningcode
left a comment
There was a problem hiding this comment.
just a question about thread safety otherwise looks good.
| } else { | ||
| try { | ||
| Object serializableObject = jsonReflectionObjectSerializer.serialize(object, logger); | ||
| Object serializableObject = getJsonReflectionObjectSerializer().serialize(object, logger); |
There was a problem hiding this comment.
Can this be called from multiple threads?
There was a problem hiding this comment.
same answer as #5600 due to vendored GSON not being thread safe JsonObjectWriter can't be used concurrently.
…uction-reflection-serializer
Instructions and example for changelogPlease add an entry to Example: ## Unreleased
### Performance
- [SDK Overhead Reduction 10] Lazily create reflection JSON serializer ([#5601](https://github.com/getsentry/sentry-java/pull/5601))If none of the above apply, you can opt out of this check by adding |
PR Stack (SDK Overhead Reduction)
📜 Description
Lazily creates
JsonReflectionObjectSerializeronly when unknown-object reflection serialization is used.Known JSON serialization paths continue to serialize directly without creating the reflection serializer. Unknown-object fallback keeps using the same reflection serializer behavior once needed.
💡 Motivation and Context
Most SDK payloads serialize through explicit
JsonSerializableimplementations or other directly supported types. Those paths do not need reflection fallback, so eagerly allocatingJsonReflectionObjectSerializerfor every writer adds unnecessary overhead.💚 How did you test it?
./gradlew :sentry:test --tests io.sentry.JsonObjectSerializerTest./gradlew spotlessApply apiDump./gradlew :sentry:test --tests io.sentry.JsonObjectSerializerTest📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps