Optimize CPU time when running d8 and r8

Pass -XX:+TieredCompilation -XX:TieredStopAtLevel=1 to the JVM to
reduce the time spent JITing, which in local experiments reduced
the CPU time of R8 while increasing the wall time, and reduced the
total number of runnable threads.

Without the new flags:
$ time out/soong/host/linux-x86/bin/r8-compat-proguard -injars out/target/common/obj/APPS/Dialer_intermediates/classes.jar ...
real	0m30.090s
user	4m35.337s
sys	0m12.853s

With the new flags:
$ time out/soong/host/linux-x86/bin/r8-compat-proguard -JXX:+TieredCompilation -JXX:TieredStopAtLevel=1 -injars out/target/common/obj/APPS/Dialer_intermediates/classes.jar ...
real	0m35.674s
user	2m45.135s
sys	0m9.531s

The increase in wall time should be offset by the better parallelism from
the reduced CPU time.

Bug: 119270658
Test: m checkbuild
Change-Id: I8fc78b5ef1f8c6f51fd97a29461b96ae2b35cada
This commit is contained in:
Colin Cross 2019-02-21 14:58:58 -08:00
parent 292d6cfd73
commit 6db4d4e613
3 changed files with 5 additions and 2 deletions

View File

@ -61,6 +61,7 @@ func init() {
pctx.StaticVariable("JavacHeapSize", "2048M")
pctx.StaticVariable("JavacHeapFlags", "-J-Xmx${JavacHeapSize}")
pctx.StaticVariable("DexFlags", "-JXX:+TieredCompilation -JXX:TieredStopAtLevel=1")
pctx.StaticVariable("CommonJdkFlags", strings.Join([]string{
`-Xmaxerrs 9999999`,

View File

@ -81,4 +81,6 @@ func makeVarsProvider(ctx android.MakeVarsContext) {
ctx.Strict("CLASS2GREYLIST", "${Class2Greylist}")
ctx.Strict("HIDDENAPI", "${HiddenAPI}")
ctx.Strict("DEX_FLAGS", "${DexFlags}")
}

View File

@ -25,7 +25,7 @@ import (
var d8 = pctx.AndroidStaticRule("d8",
blueprint.RuleParams{
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
`${config.D8Cmd} --output $outDir $d8Flags $in && ` +
`${config.D8Cmd} ${config.DexFlags} --output $outDir $d8Flags $in && ` +
`${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` +
`${config.MergeZipsCmd} -D -stripFile "**/*.class" $out $outDir/classes.dex.jar $in`,
CommandDeps: []string{
@ -40,7 +40,7 @@ var r8 = pctx.AndroidStaticRule("r8",
blueprint.RuleParams{
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
`rm -f "$outDict" && ` +
`${config.R8Cmd} -injars $in --output $outDir ` +
`${config.R8Cmd} ${config.DexFlags} -injars $in --output $outDir ` +
`--force-proguard-compatibility ` +
`--no-data-resources ` +
`-printmapping $outDict ` +