From a2c463438d192ba6552b8f01e2c69bd3846e30ef Mon Sep 17 00:00:00 2001 From: Tor Norbye Date: Thu, 22 Mar 2012 18:17:21 -0700 Subject: Speed up loadPublicResources() The FrameworkResources method which loads in the public resources takes about ~500ms of the target loading time. This changeset optimizes this down to < 50ms using the following three optimizations: 1) Precompute a map from names to ResourceItems before processing the public names. Before this, it would search sequentially through the name list, which when done n times meant O(n^2); we can construct the map in O(n) and then perform n lookups in O(1) => O(n). Also, be smart about which maps we precompute names for: the ResourceType.PUBLIC and ResourceType.DECLARE_STYLEABLE types have about 2,000 items, none of which are public, so skip precomputing maps for these two. (However, keep the linear search around such that if any are exported in the future the code will work correctly. Similarly, we know "roughly" the size of the final public maps, so initialize them in the right size range such that they don't have to do any internal resize+copy operations as we insert into them. 2) In android-15 there are 1500 new elements in the public xml file, which were being processed, doubling the number of exported symbols. Limit the processing to only the tags. 3) Switch from DOM parsing to pull parsing. This helps since more than half the file consists of elements, and we can ignore whitespace and id attributes etc, so there is much less object creation involved. Change-Id: I4761e1182b9bc0c50fe94aea7dcd9690754c7908 --- eclipse/dictionary.txt | 2 ++ 1 file changed, 2 insertions(+) (limited to 'eclipse') diff --git a/eclipse/dictionary.txt b/eclipse/dictionary.txt index dca9b23..c1640c0 100644 --- a/eclipse/dictionary.txt +++ b/eclipse/dictionary.txt @@ -192,6 +192,8 @@ popup popups pre precompiler +precompute +precomputing pref prefs preload -- cgit v1.1