fix: resolve #1194 — 【已解决,请切换到1.9.14版本】反射隔离Application和ApplicationLike类导致getResources方法耗时显著增加#1791
Open
Nam0101 wants to merge 3 commits into
Conversation
…tionLike类导致getResources方法耗时显著增加 Fixes Tencent#1194 Signed-off-by: Nguyen Van Nam <nam.nv205106@gmail.com>
…tionLike类导致getResources方法耗时显著增加 Fixes Tencent#1194 Signed-off-by: Nguyen Van Nam <nam.nv205106@gmail.com>
…tionLike类导致getResources方法耗时显著增加 Fixes Tencent#1194 Signed-off-by: Nguyen Van Nam <nam.nv205106@gmail.com>
Member
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
fix: resolve #1194 — 【已解决,请切换到1.9.14版本】反射隔离Application和ApplicationLike类导致getResources方法耗时显著增加
Problem
Severity:
High| File:tinker-android/tinker-android-anno/src/main/resources/TinkerAnnoApplication.tmplThis template generates the user's Application class that delegates to ApplicationLike. Since 1.9.9, calls like getResources() were routed through reflection to prevent the compiler from inlining ApplicationLike methods into the Application class (which would break hot-fix capability for those methods). However, reflection on every getResources() call is extremely costly because Android framework code calls getResources() very frequently (e.g., during view inflation, resource lookup, etc.). The fix should use a non-reflection mechanism that still defeats inlining.
Solution
Modify the template so that overrides like getResources(), getAssets(), getBaseContext(), getClassLoader(), etc. call ApplicationLike methods directly (e.g.,
applicationLike.getResources()) rather than viaMethod.invoke(). To still prevent inlining across the Application/ApplicationLike boundary on systems where this is a concern, rely on the fact that ApplicationLike is loaded via a different ClassLoader (the patched dex ClassLoader) at runtime, which naturally prevents the ART compiler from inlining across ClassLoader boundaries. Alternatively, mark the relevant ApplicationLike methods as non-final and ensure they remain in a separately-loaded dex. For older Android versions where this is insufficient, a lightweight indirection (e.g., a volatile field read or an interface dispatch) is far cheaper than reflection. Branch the generated code byBuild.VERSION.SDK_INTif behavior must differ per system version.Changes
tinker-android/tinker-android-anno/src/main/resources/TinkerAnnoApplication.tmpl(modified)tinker-android/tinker-android-anno/src/test/java/com/tencent/tinker/anno/test/AnnotationProcessorTest.java(new)tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/app/ApplicationLike.java(new)Testing
Note: this change was drafted with AI assistance and reviewed locally before submission.