summaryrefslogtreecommitdiff
path: root/libs/androidfw/AttributeResolution.cpp
diff options
context:
space:
mode:
authorRyan Mitchell <rtmitchell@google.com>2020-10-05 14:24:35 -0700
committerRyan Mitchell <rtmitchell@google.com>2020-11-12 08:13:48 -0800
commit87e89546b66da6d5098b46ff9b868ef82a753932 (patch)
treec99f5e1e0f712e5fcf88c928b8ed03f96b067392 /libs/androidfw/AttributeResolution.cpp
parentc75c2e092218a7d77be39c89bfba7dd2b4823ac1 (diff)
Cache resolved theme values
When calling Resources#obtainStyledAttributes, if a value for an attribute is supplied from the theme, and the value in the theme is a reference to a resource, the reference will be resolved using AssetManager2::ResolveReference each time the value from the theme is selected. This causes Resources#obtainStyledAttributes to do repeated work every time the same attribute is supplied from the theme in multiple invocations. Caching the result of ResolveReference reduces the cost of this repeated work and reduces the amount of time needed to inflate views. Before: com.android.resources.perf (3 Tests) [1/3] com.android.resources.perf.PerfTest#youtube: PASSED (11.748s) youtube_ns_median: 95490747 youtube_ns_standardDeviation: 7282249 youtube_ns_mean: 98442515 [2/3] com.android.resources.perf.PerfTest#maps: PASSED (10.862s) maps_ns_standardDeviation: 4484213 maps_ns_mean: 87912988 maps_ns_median: 86325549 [3/3] com.android.resources.perf.PerfTest#gmail: PASSED (24.034s) gmail_ns_median: 282175838 gmail_ns_standardDeviation: 6560876 gmail_ns_mean: 282869146 After: com.android.resources.perf (3 Tests) [1/3] com.android.resources.perf.PerfTest#youtube: PASSED (11.245s) youtube_ns_median: 92292347 youtube_ns_standardDeviation: 5899906 youtube_ns_mean: 93045239 [2/3] com.android.resources.perf.PerfTest#maps: PASSED (10.583s) maps_ns_standardDeviation: 7567929 maps_ns_mean: 81895979 maps_ns_median: 78647883 [3/3] com.android.resources.perf.PerfTest#gmail: PASSED (21.439s) gmail_ns_median: 229185043 gmail_ns_standardDeviation: 8770133 gmail_ns_mean: 232561234 These tests were done on a Pixel 3 and with cpu settings configured by libs/hwui/tests/scripts/prep_generic.sh: Locked CPUs 4,5,6,7 to 1459200 / 2803200 KHz Disabled CPUs 0,1,2,3 Bug: 170232288 Test: atest ResourcesPerfWorkloads Change-Id: I1e9e9acaa40fa60475a0e55230e11243f5b69b39
Diffstat (limited to 'libs/androidfw/AttributeResolution.cpp')
-rw-r--r--libs/androidfw/AttributeResolution.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/libs/androidfw/AttributeResolution.cpp b/libs/androidfw/AttributeResolution.cpp
index 71919fdbb736..347b4ec8346c 100644
--- a/libs/androidfw/AttributeResolution.cpp
+++ b/libs/androidfw/AttributeResolution.cpp
@@ -39,8 +39,7 @@ class XmlAttributeFinder
: public BackTrackingAttributeFinder<XmlAttributeFinder, size_t> {
public:
explicit XmlAttributeFinder(const ResXMLParser* parser)
- : BackTrackingAttributeFinder(
- 0, parser != nullptr ? parser->getAttributeCount() : 0),
+ : BackTrackingAttributeFinder(0, parser != nullptr ? parser->getAttributeCount() : 0),
parser_(parser) {}
inline uint32_t GetAttribute(size_t index) const {
@@ -178,7 +177,7 @@ base::expected<std::monostate, IOError> ResolveAttrs(Theme* theme, uint32_t def_
value = *attr_value;
DEBUG_LOG("-> From theme: type=0x%x, data=0x%08x", value.type, value.data);
- const auto result = assetmanager->ResolveReference(value);
+ const auto result = assetmanager->ResolveReference(value, true /* cache_value */);
if (UNLIKELY(IsIOError(result))) {
return base::unexpected(GetIOError(result.error()));
}
@@ -310,7 +309,7 @@ base::expected<std::monostate, IOError> ApplyStyle(Theme* theme, ResXMLParser* x
value = *attr_value;
DEBUG_LOG("-> From theme: type=0x%x, data=0x%08x", value.type, value.data);
- auto result = assetmanager->ResolveReference(value);
+ auto result = assetmanager->ResolveReference(value, true /* cache_value */);
if (UNLIKELY(IsIOError(result))) {
return base::unexpected(GetIOError(result.error()));
}