-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NewThreadWorker.tryEnableCancelPolicy doing costly reflection on Android #3119
Comments
Woah. If the signature of the to-be-reflected method is known why is a direct lookup not being done? |
@digitalbuddha You can use the system property "rx.scheduler.jdk6.purge-force" set to "true" to avoid the loop. The reason for the loop is to avoid NoSuchMethodException being thrown on JDK 6 which is more costly than looping through ~70 methods. Although I admit evaluating that all the time is unnecessary as Executors.newScheduledExecutor() won't change is ability during runtime. |
Thankfully that property just squeezes under Android's 31 character max at 29 chars! |
Can we use |
My google search indicates the method |
The |
@akarnokd what do you mean by
? Documentation: http://developer.android.com/reference/android/os/Build.VERSION.html#SDK_INT |
Android is one platform |
Great. Would you like to submit a PR? |
Just pushed the PR #3121. Android supports |
Little Gist for those who want to fix this in Android app with RxJava: https://gist.github.com/artem-zinnatullin/51b6c6720ecb8a2a71eb |
Your gist says "static initializer block" and then proceeds to use an instance initializer block. |
Such a stupid mistake…Uh. Thanks. |
I was analyzing startup time in the NY Times Android app and started method profiling on startup using Android Device Monitor. Total time from the beginning of the application class to end of onCreate for first activity is roughly 2.2seconds. Diving deeper I was able to observe that
NewThreadWorker.tryEnableCancelPolicy
was taking 1200ms to execute with the offending line being
for (Method m : exec.getClass().getMethods())
(1017ms)Diving deeper shows a call to
CollectionUtils.removeDuplicates (992 ms)
which will call
collection.sort
(719ms)&
reflect.compare
(259ms).tryEnableCancelPolicy has the following comment:
I tried creating a Scheduler from an Executor but still hit the offending code. Is there a way to avoid this code or fix the large performance hit that it is causing?
The text was updated successfully, but these errors were encountered: