Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7cb9e5f6 authored by Edgar Arriaga's avatar Edgar Arriaga
Browse files

Optimization: remove duplicated flags computations for getInstalledPackages

Below are some test runs that show 100 iterations of getInstalledPackages ran
at activity startup of touchlatency app to demonstrate the perf cost.

R Baseline:
https://screenshot.googleplex.com/PnVi5APraJo
https://pprof.corp.google.com/?id=dc105ca9592f8367c381e2dcf7f1847d

R Optimized:
https://pprof.corp.google.com/?id=2d1d9fadc20bcc61d41bd52116bd94e3
https://screenshot.googleplex.com/OAwJnvwPqPH

Savings: 8% of system_server binder response time when the call is executed.

In terms total binder transaction time. Savings are 2% of the total
binder call time.

Test: atest FrameworksServicesTests:PackageParserTest
Test: atest FrameworksServicesTests:PackageParserLegacyCoreTest
Test: atest FrameworksServicesTests:ScanTests
Test: atest FrameworksServicesTests:ParallelPackageParserTest

Change-Id: I2de9cf1f754a505239d4416e1fc70bf77932c5db
parent 03fb4e10
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -350,9 +350,6 @@ public class PackageInfoWithoutStateUtils {
        // TODO(b/135203078): Consolidate the data directory logic, remove initForUser
        ai.initForUser(userId);

        ai.flags = appInfoFlags(pkg);
        ai.privateFlags = appInfoPrivateFlags(pkg);

        if ((flags & PackageManager.GET_META_DATA) == 0) {
            ai.metaData = null;
        }
+7 −1
Original line number Diff line number Diff line
@@ -842,9 +842,15 @@ public class ParsingPackageImpl implements ParsingPackage, Parcelable {
    @Deprecated
    @Override
    public ApplicationInfo toAppInfoWithoutState() {
        ApplicationInfo appInfo = new ApplicationInfo();
        ApplicationInfo appInfo = toAppInfoWithoutStateWithoutFlags();
        appInfo.flags = PackageInfoWithoutStateUtils.appInfoFlags(this);
        appInfo.privateFlags = PackageInfoWithoutStateUtils.appInfoPrivateFlags(this);
        return appInfo;
    }

    @Override
    public ApplicationInfo toAppInfoWithoutStateWithoutFlags() {
        ApplicationInfo appInfo = new ApplicationInfo();

        appInfo.appComponentFactory = appComponentFactory;
        appInfo.backupAgentName = backupAgentName;
+5 −0
Original line number Diff line number Diff line
@@ -850,4 +850,9 @@ public interface ParsingPackageRead extends Parcelable {

    // TODO(b/135203078): Hide and enforce going through PackageInfoUtils
    ApplicationInfo toAppInfoWithoutState();

    /**
     * same as toAppInfoWithoutState except without flag computation.
     */
    ApplicationInfo toAppInfoWithoutStateWithoutFlags();
}
+23 −5
Original line number Diff line number Diff line
@@ -234,8 +234,9 @@ public class PackageInfoUtils {
        info.primaryCpuAbi = AndroidPackageUtils.getPrimaryCpuAbi(pkg, pkgSetting);
        info.secondaryCpuAbi = AndroidPackageUtils.getSecondaryCpuAbi(pkg, pkgSetting);

        info.flags |= appInfoFlags(pkg, pkgSetting);
        info.privateFlags |= appInfoPrivateFlags(pkg, pkgSetting);
        info.flags |= appInfoFlags(info.flags, pkgSetting);
        info.privateFlags |= appInfoPrivateFlags(info.privateFlags, pkgSetting);

        return info;
    }

@@ -449,9 +450,18 @@ public class PackageInfoUtils {
    public static int appInfoFlags(AndroidPackage pkg, @Nullable PackageSetting pkgSetting) {
        // TODO(b/135203078): Add setting related state
        // @formatter:off
        int flags = PackageInfoWithoutStateUtils.appInfoFlags(pkg)
        int pkgWithoutStateFlags = PackageInfoWithoutStateUtils.appInfoFlags(pkg)
                | flag(pkg.isSystem(), ApplicationInfo.FLAG_SYSTEM)
                | flag(pkg.isFactoryTest(), ApplicationInfo.FLAG_FACTORY_TEST);

        return appInfoFlags(pkgWithoutStateFlags, pkgSetting);
        // @formatter:on
    }

    /** @see ApplicationInfo#flags */
    public static int appInfoFlags(int pkgWithoutStateFlags, @NonNull PackageSetting pkgSetting) {
        // @formatter:off
        int flags = pkgWithoutStateFlags;
        if (pkgSetting != null) {
            flags |= flag(pkgSetting.getPkgState().isUpdatedSystemApp(), ApplicationInfo.FLAG_UPDATED_SYSTEM_APP);
        }
@@ -461,9 +471,8 @@ public class PackageInfoUtils {

    /** @see ApplicationInfo#privateFlags */
    public static int appInfoPrivateFlags(AndroidPackage pkg, @Nullable PackageSetting pkgSetting) {
        // TODO(b/135203078): Add setting related state
        // @formatter:off
        return PackageInfoWithoutStateUtils.appInfoPrivateFlags(pkg)
        int pkgWithoutStateFlags = PackageInfoWithoutStateUtils.appInfoPrivateFlags(pkg)
                | flag(pkg.isSystemExt(), ApplicationInfo.PRIVATE_FLAG_SYSTEM_EXT)
                | flag(pkg.isPrivileged(), ApplicationInfo.PRIVATE_FLAG_PRIVILEGED)
                | flag(pkg.isOem(), ApplicationInfo.PRIVATE_FLAG_OEM)
@@ -471,6 +480,15 @@ public class PackageInfoUtils {
                | flag(pkg.isProduct(), ApplicationInfo.PRIVATE_FLAG_PRODUCT)
                | flag(pkg.isOdm(), ApplicationInfo.PRIVATE_FLAG_ODM)
                | flag(pkg.isSignedWithPlatformKey(), ApplicationInfo.PRIVATE_FLAG_SIGNED_WITH_PLATFORM_KEY);
        return appInfoPrivateFlags(pkgWithoutStateFlags, pkgSetting);
        // @formatter:on
    }

    /** @see ApplicationInfo#privateFlags */
    public static int appInfoPrivateFlags(int pkgWithoutStateFlags, @Nullable PackageSetting pkgSetting) {
        // @formatter:off
        // TODO: Add state specific flags
        return pkgWithoutStateFlags;
        // @formatter:on
    }

+6 −0
Original line number Diff line number Diff line
@@ -300,6 +300,12 @@ public interface AndroidPackage extends PkgAppInfo, PkgPackageInfo, ParsingPacka
    @NonNull
    ApplicationInfo toAppInfoWithoutState();

    /**
     * Same as toAppInfoWithoutState except it does not compute any flags.
     */
    @NonNull
    ApplicationInfo toAppInfoWithoutStateWithoutFlags();

    /**
     * TODO(b/135203078): Remove usages?
     * @return a mock of what the previous package.applicationInfo would've returned for logging
Loading