Improve performance of generating JS class from Metadata #1824
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.
Java classes can have 100s and even thousands of methods and properties on them, for example
android.view.View
has 673 methods on it, similarlyandroid.R
class has always been slow to access since it has many nested classes. A common issue that many of us have faced and tried to workaround in various ways using metadata filtering and other hacks. But it doesn't properly fix the problem, even classes that have a few methods, take too long to load the first time. This can have affect on TTI, navigating to new pages that access a java class my many methods because everything is running on UI thread.This PR tries to fix the issue once and for all, loading classes is now super fast. Almost as fast as the iOS runtime. But how?
android.R.integer
. For example accessingandroid.R.integer
only loads methods, properties onandroid.R
&android.R.integer
and any base classes. Previously it would load all classes inandroid.R
then load your classandroid.R.integer
which would take 100s of ms!std::unordered_map
and for every method it adds to the prototype, it will check whether there is existing method information of a method with same name. This is fine for small classes but when class is huge, the lookup becomes quite slow. To fix this we have usedrobin_hood::unordered_map
that results in great performance gain.There are still places that could see improvement but as of now with theses changes, most classes will load in 0.1-0.2ms.
This is a big change and is spread across multiple files.