Title: Reduce per-instance lock overhead in SentryId and SpanId · Issue #5644 · getsentry/sentry-java · GitHub
Open Graph Title: Reduce per-instance lock overhead in SentryId and SpanId · Issue #5644 · getsentry/sentry-java
X Title: Reduce per-instance lock overhead in SentryId and SpanId · Issue #5644 · getsentry/sentry-java
Description: Problem Statement SentryId and SpanId store their string value behind a LazyEvaluator
Open Graph Description: Problem Statement SentryId and SpanId store their string value behind a LazyEvaluator
X Description: Problem Statement SentryId and SpanId store their string value behind a LazyEvaluator<String>. Every instance therefore allocates: a LazyEvaluator object, which in turn allocates an AutoClosa...
Opengraph URL: https://github.com/getsentry/sentry-java/issues/5644
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Reduce per-instance lock overhead in SentryId and SpanId","articleBody":"### Problem Statement\n\n`SentryId` and `SpanId` store their string value behind a `LazyEvaluator\u003cString>`. Every instance therefore allocates:\n\n* a `LazyEvaluator` object, which in turn allocates\n* an `AutoClosableReentrantLock` (a `ReentrantLock` subclass, including its internal `Sync` object), plus\n* a captured lambda\n\n…all to guard a single `String`.\n\nThese two types are allocated at very high frequency — one `SentryId` per event/transaction and one `SpanId` per span — so the per-instance lock machinery is far heavier than the value it protects. This is the worst place in the SDK for lock weight relative to the guarded object.\n\nIt is most clearly wasteful in the eager constructors, where the string already exists at construction time and there is no laziness benefit at all:\n\n* `SpanId(String value)` → `new LazyEvaluator\u003c>(() -> value)`\n* `SentryId(String)` → `new LazyEvaluator\u003c>(() -> normalize(normalized))` / `() -> normalized`\n\nThe no-arg / `UUID` constructors do benefit from deferring UUID-string generation (added in #3770 / #3818), but a full per-instance `ReentrantLock` is a heavy way to guard generation of one string.\n\n### Solution Brainstorm\n\nReplace the `LazyEvaluator\u003cString>` in both classes with a lighter `volatile`-based lazy field:\n\n* Eager (string-arg) constructors set the value directly — no lazy wrapper.\n* Lazy constructors keep deferring generation, using a plain `volatile` + double-checked `synchronized (this)` block (no extra lock allocation). Proper synchronization is still required because UUID generation is non-idempotent (two racing threads would otherwise produce different ids).\n\nThis drops the `LazyEvaluator` + `ReentrantLock` + lambda allocations per id while preserving existing behaviour and laziness. Follow-up to the SDK Overhead Reduction work (#5499).","author":{"url":"https://github.com/runningcode","@type":"Person","name":"runningcode"},"datePublished":"2026-06-25T14:58:23Z","url":"https://github.com/getsentry/sentry-java/issues/5644"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5754fb02-f471-1bfc-e87d-6f38f6fa5e44 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8DBC:15EB96:A4B665:E0705A:6B04834E |
| html-safe-nonce | 169714fe0404aaef03061f8cbd6a08347b448775fbeb2c220ad102f31e0b9c48 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4REJDOjE1RUI5NjpBNEI2NjU6RTA3MDVBOjZCMDQ4MzRFIiwidmlzaXRvcl9pZCI6IjUwMzI3NzI5ODkxMDg5MTI5NzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | aea6b91e70be3a9f0a33d1a4c0e50c506618c640fd27e4d0aea676752f424126 |
| hovercard-subject-tag | issue:4744942561 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-java/5644/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b13bd92fbde2e2c52dea6f2b06aabac414dd917bb293ff3d76cafbceef8cc9e4/getsentry/sentry-java/issues/5644 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b13bd92fbde2e2c52dea6f2b06aabac414dd917bb293ff3d76cafbceef8cc9e4/getsentry/sentry-java/issues/5644 |
| og:image:alt | Problem Statement SentryId and SpanId store their string value behind a LazyEvaluator |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | runningcode |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1d5c152376e38b7d2e37f3d5179be29a73bee93b85110da28a4eebe1159cdc70 |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-java git https://github.com/getsentry/sentry-java.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3368190 |
| octolytics-dimension-repository_nwo | getsentry/sentry-java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3368190 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f5017e8ff4ea25a8011fcf0f2a0e430c60dc86c8 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width