Skip to content

Commit

Permalink
BEGIN_PUBLIC
Browse files Browse the repository at this point in the history
Expand baseline profile wildcards before optimizer tools see the profiles.
END_PUBLIC

This addresses what is described here: b/295087579
In particular, the human-readable format for baseline profiles can contain
wildcards (eg. "LSomeClass*"). Profgen can expand these, and thus AppReduce
does not have to process them.
Note: This does not expand anything provided by the `startup_profiles`
attribute. The assumption is this isn't necessary as these would
be generated by a device, and thus shouldn't have wildcards.
Expanding wildcards here could arguably be an unnecessary cost for
build performance. Currently, if AppReduce encounters wildcards, it will just ignore them.

RELNOTES: Expands baseline profile wildcards before optimizer tools see them.
PiperOrigin-RevId: 556095126
Change-Id: Ie6cb65ebbf0131da098504fe0d27ade0b967ae57
  • Loading branch information
Googler authored and Copybara-Service committed Aug 11, 2023
1 parent 2c8f6bb commit 52c3566
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Expand Up @@ -145,4 +145,14 @@ public Artifact mergeBaselineProfiles(
public Artifact mergeStartupProfiles(RuleContext ruleContext, String baselineProfileDir) {
return null;
}

/* Bazel does not currently support baseline profiles in the final apk. */
@Override
public Artifact expandBaselineProfileWildcards(
RuleContext ruleContext,
Artifact deployJar,
Artifact mergedStaticProfile,
String baselineProfileDir) {
return null;
}
}
Expand Up @@ -545,17 +545,24 @@ public static RuleConfiguredTargetBuilder createAndroidBinary(
if (baselineprofileProvider == null
&& Allowlist.hasAllowlist(ruleContext, "allow_baseline_profiles_optimizer_integration")
&& Allowlist.isAvailable(ruleContext, "allow_baseline_profiles_optimizer_integration")) {
if (!proguardSpecs.isEmpty()) {
// This is only needed for optimized builds since otherwise the dexer doesn't process this.
startupProfile = androidSemantics.mergeStartupProfiles(ruleContext, baselineProfileDir);
}
baselineProfile =
androidSemantics.mergeBaselineProfiles(
ruleContext,
baselineProfileDir,
// Include startup profiles if the optimizer is disabled since profiles won't be
// merged in the optimizer.
proguardSpecs.isEmpty());
if (!proguardSpecs.isEmpty()) {
// This is only needed for optimized builds since otherwise the dexer doesn't process this.
startupProfile = androidSemantics.mergeStartupProfiles(ruleContext, baselineProfileDir);
// Wildcards only need to be expanded for optimized builds since if these aren't consumed by
// the optimizer, they can just be expanded during profile compilation instead.
// Start-up profiles are not expanded because it shouldn't be necessary as these should
// contain profiles generated by devices on start-up.
baselineProfile =
androidSemantics.expandBaselineProfileWildcards(
ruleContext, binaryJar, baselineProfile, baselineProfileDir);
}
}
ProguardOutput proguardOutput =
applyProguard(
Expand Down
Expand Up @@ -118,6 +118,13 @@ Artifact mergeBaselineProfiles(
/** The merged startup profiles from the {@code startup_profiles} attribute. */
Artifact mergeStartupProfiles(RuleContext ruleContext, String baselineProfileDir);

/** Expands any wildcards present in a baseline profile, and returns the new expanded artifact. */
public Artifact expandBaselineProfileWildcards(
RuleContext ruleContext,
Artifact deployJar,
Artifact mergedStaticProfile,
String baselineProfileDir);

/** The artifact for ART profile information, given a particular merged profile. */
Artifact compileBaselineProfile(
RuleContext ruleContext,
Expand Down

0 comments on commit 52c3566

Please sign in to comment.