Skip to content

Avoid constructing a full SentryOptions for the static globalScope #5708

Description

@runningcode

Problem

Sentry's static initializer creates globalScope = new Scope(SentryOptions.empty()) (sentry/src/main/java/io/sentry/Sentry.java:68) at class-load time — a complete SentryOptions (sub-options objects, ~10 concurrent collections, plus the two default integrations added in the ctor) and a full Scope (preallocated breadcrumb ring, ~14 collections, locks). All of it is superseded moments later when Sentry.init calls globalScope.replaceOptions(options) (Sentry.java:337).

Under auto-init this allocation happens on the main thread at ContentProvider time, before Application.onCreate.

Proposal

Use a shared minimal/immutable empty-options singleton, or defer globalScope construction until first access (lazy holder). Pure allocation win at class-load; combine with the lazy sub-options investigation.

Constraints

  • SentryOptions.empty() semantics: some code paths rely on a mutable options instance pre-init (e.g. globalScope observers?); audit Scope usage before replaceOptions.

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