sentry-java: Sentry.init takes too much time and blocks ui thread

On some android devices Sentry initialization may take up to 1-2 seconds what could be critical for a lot of apps. Sentry init

The root of the problem is static initialization block in Lookup class which tries to find sentry.properties files in classpath. Sentry uses this Lookup class during initialization stage for getting initialization params from dsn. Even if all needed information is presented in dsn Sentry tries to load properties file because of static block that may take a lot of time.

@mcomella have already mentioned this problem in similar issue.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 7
  • Comments: 17 (4 by maintainers)

Commits related to this issue

Most upvoted comments

This article explains why Android’s resources are so slow.

I’m working around this problem by overriding all the methods of AndroidSentryClientFactory that use Lookup.lookup to instead just look in an instance of Properties which I store in my client factory class.

A proper solution to this could be to add a lookup method to SentryClientFactory which AndroidSentryClientFactory could override to not try to find a sentry.properties file in resources, and instead access the properties through the assets mechanism. This is what the java.time backport for Android does to avoid the slow resources mechanism when loading its timezone database, so the properties would instead be accessed like context.getAssets().open("sentry.properties").

For backwards compatibility, it could still look for the config in the resources folder if it doesn’t find the config as an asset, and we print a warning about this happening to say they can get better startup performance if they put the properties file in the assets folder

You can set a ResourceLoader via Sentry.init now through options:

SentryOptions options = new SentryOptions();
options.ResourceLoader = new AndroidAssetsResourceLoader(ctx);
Sentry.init(options);

Feel free to reopen if there’s any issue.