| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…plementation ScheduledThreadPoolExecutor's internal DelayedWorkQueue is a heap that resizes dynamically (50% growth from initial capacity 16). prewarm() was introduced to pre-grow that array during init, but doing so on the main thread is itself the worst possible time to trigger allocations — and the queue resize cost is only ~8µs anyway. This replaces the whole approach: a custom executor backed by a PriorityQueue pre-allocated to INITIAL_QUEUE_CAPACITY=64 at construction time. The backing array never resizes during normal SDK operation. A single daemon worker thread uses Object.wait/notifyAll for precise wakeup on scheduled tasks. prewarm() becomes a documented no-op. Key properties: - No array resize at runtime: queue pre-allocated at construction - Precise scheduling: worker sleeps until next task triggerTime, wakes immediately when an earlier task is enqueued - MAX_QUEUE_SIZE (271) and purge-on-overflow semantics preserved - ScheduledTask<T> extends FutureTask<T> for free Future<T> contract - Drops @testonly ScheduledThreadPoolExecutor constructor (nothing to inject) Refs #5681
Old tests verified delegation to a mocked ScheduledThreadPoolExecutor. New tests verify actual executor behavior: task execution, scheduling, close semantics, queue limit enforcement, cancelled-task purging, and trigger-time ordering.
Instructions and example for changelogPlease add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number. Example: ## Unreleased
### Features
- Replace SentryExecutorService with pre-allocated queue ([#5717](https://github.com/getsentry/sentry-java/pull/5717))If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label. |
Sorry, something went wrong.
📲 Install BuildsAndroid
|
Sorry, something went wrong.
Performance metrics 🚀
Baseline results on branch: mainStartup times
App size
|
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Problem
ScheduledThreadPoolExecutor's internal DelayedWorkQueue is a min-heap that grows dynamically (50% per resize, starting from 16). prewarm() was introduced to pre-grow that array during Sentry.init — but init runs on the main thread, which is exactly when ANR risk is highest. The resize cost it avoids is only ~8µs; the prewarm itself adds ~100µs and is the more expensive operation.
More fundamentally, ScheduledThreadPoolExecutor's queue isn't replaceable, so there was no clean way to fix this without a custom implementation.
Solution
Replace SentryExecutorService with a custom implementation backed by:
prewarm() is now a documented no-op. The MAX_QUEUE_SIZE = 271 hard limit and purge-on-overflow behaviour are preserved unchanged.
What changed
Notes
cc @romtsn
--
View Junior Session in Sentry