File tree Expand file tree Collapse file tree 3 files changed +16
-4
lines changed
sentry-android-core/src/main/java/io/sentry/android/core/internal/modules
sentry/src/main/java/io/sentry/internal/modules Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Original file line number Diff line number Diff line change 1818### Improvements
1919
2020- Make user interaction tracing faster and do fewer allocations ([ #4347 ] ( https://github.com/getsentry/sentry-java/pull/4347 ) )
21+ - Pre-load modules on a background thread upon SDK init ([ #4348 ] ( https://github.com/getsentry/sentry-java/pull/4348 ) )
2122
2223## 8.8.0
2324
Original file line number Diff line number Diff line change @@ -21,6 +21,10 @@ public final class AssetsModulesLoader extends ModulesLoader {
2121 public AssetsModulesLoader (final @ NotNull Context context , final @ NotNull ILogger logger ) {
2222 super (logger );
2323 this .context = ContextUtils .getApplicationContext (context );
24+
25+ // pre-load modules on a bg thread to avoid doing so on the main thread in case of a crash/error
26+ //noinspection Convert2MethodRef
27+ new Thread (() -> getOrLoadModules ()).start ();
2428 }
2529
2630 @ Override
Original file line number Diff line number Diff line change 11package io .sentry .internal .modules ;
22
33import io .sentry .ILogger ;
4+ import io .sentry .ISentryLifecycleToken ;
45import io .sentry .SentryLevel ;
6+ import io .sentry .util .AutoClosableReentrantLock ;
57import java .io .BufferedReader ;
68import java .io .IOException ;
79import java .io .InputStream ;
@@ -21,18 +23,23 @@ public abstract class ModulesLoader implements IModulesLoader {
2123
2224 public static final String EXTERNAL_MODULES_FILENAME = "sentry-external-modules.txt" ;
2325 protected final @ NotNull ILogger logger ;
24- private @ Nullable Map <String , String > cachedModules = null ;
26+
27+ private final @ NotNull AutoClosableReentrantLock modulesLock = new AutoClosableReentrantLock ();
28+ private volatile @ Nullable Map <String , String > cachedModules = null ;
2529
2630 public ModulesLoader (final @ NotNull ILogger logger ) {
2731 this .logger = logger ;
2832 }
2933
3034 @ Override
3135 public @ Nullable Map <String , String > getOrLoadModules () {
32- if (cachedModules != null ) {
33- return cachedModules ;
36+ if (cachedModules == null ) {
37+ try (final @ NotNull ISentryLifecycleToken ignored = modulesLock .acquire ()) {
38+ if (cachedModules == null ) {
39+ cachedModules = loadModules ();
40+ }
41+ }
3442 }
35- cachedModules = loadModules ();
3643 return cachedModules ;
3744 }
3845
You can’t perform that action at this time.
0 commit comments