Skip to content

Lazy-allocate the breadcrumb queue in Scope #5709

Description

@runningcode

Problem

Each Scope preallocates its breadcrumb ring buffer at maxBreadcrumbs capacity (default 100) in the constructor (createBreadcrumbsList in sentry/src/main/java/io/sentry/Scope.java; the vendored CircularFifoQueue allocates its backing array eagerly). Init alone creates three scopes — global (Sentry.java:68), root + isolation (Sentry.java:339-340) — and scope forking copies pay the same, so the arrays multiply across the process lifetime even when breadcrumbs are disabled (maxBreadcrumbs = 0 is handled, but the default path always allocates).

Proposal

Allocate the queue on first addBreadcrumb. Check the same pattern for other per-scope members (FeatureFlagBuffer, attachments, eventProcessors) — several could be empty-singleton until first write.

Constraints

  • Scope.clone/fork paths and the synchronized queue wrapper need to handle the not-yet-allocated state without racing; keep the fast path allocation-free.

Allocation/GC-pressure win; verify with an ART allocation trace (below cold-start macrobenchmark noise individually).

Metadata

Metadata

Assignees

No one assigned

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions