From 23f1be2d5d04f6ad49b2f06885544fd7292a903e Mon Sep 17 00:00:00 2001 From: Kohsuke Yatoh Date: Wed, 10 Aug 2022 01:58:17 +0000 Subject: [PATCH] Preload font before TypefaceSerializationPerfTest. This CL disables lazy font loading by preloading font in setUp(), in order to stabilize testSerializeFontMap() results. In testSerializeFontMap(), the first serializeFontMap() takes 20x time due to lazy font loading (first call 40ms / avg 2ms on oriole). This makes test results unstable by reducing the number of iterations. ManualBenchmarkState calculates the number of iterations ('mMaxIterations') as follows: mMaxIterations = (int) (mTargetTestDurationNs / (warmupDuration / iterations)); where 'iterations' is the number of iterations done in warmup stage. If the first iteration in warmup stage takes unusually long, 'iterations' becomes small and mMaxIterations will be smaller as well. Bug: 239758440 Test: atest CorePerfTests:android.graphics.perftests.TypefaceSerializationPerfTest#testSerializeFontMap Change-Id: I3181962a1807cb7b4ecbc8e26fe629b9f530e1c1 --- .../perftests/TypefaceSerializationPerfTest.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/apct-tests/perftests/core/src/android/graphics/perftests/TypefaceSerializationPerfTest.java b/apct-tests/perftests/core/src/android/graphics/perftests/TypefaceSerializationPerfTest.java index 1e2650dbfdc48..3a23b54916782 100644 --- a/apct-tests/perftests/core/src/android/graphics/perftests/TypefaceSerializationPerfTest.java +++ b/apct-tests/perftests/core/src/android/graphics/perftests/TypefaceSerializationPerfTest.java @@ -28,6 +28,7 @@ import android.util.Log; import androidx.test.filters.LargeTest; import androidx.test.runner.AndroidJUnit4; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -50,6 +51,14 @@ public class TypefaceSerializationPerfTest { @Rule public PerfManualStatusReporter mPerfManualStatusReporter = new PerfManualStatusReporter(); + @Before + public void setUp() { + // Parse and load the preinstalled fonts in the test process so that: + // (1) Updated fonts do not affect test results. + // (2) Lazy-loading of fonts does not affect test results (esp. testSerializeFontMap). + Typeface.loadPreinstalledSystemFontMap(); + } + @ManualBenchmarkState.ManualBenchmarkTest( warmupDurationNs = WARMUP_DURATION_NS, targetTestDurationNs = TARGET_TEST_DURATION_NS) @@ -61,8 +70,12 @@ public class TypefaceSerializationPerfTest { long elapsedTime = 0; while (state.keepRunning(elapsedTime)) { long startTime = System.nanoTime(); - Typeface.serializeFontMap(systemFontMap); + SharedMemory sharedMemory = Typeface.serializeFontMap(systemFontMap); elapsedTime = System.nanoTime() - startTime; + sharedMemory.close(); + android.util.Log.i(TAG, + "testSerializeFontMap isWarmingUp=" + state.isWarmingUp() + + " elapsedTime=" + elapsedTime); } }