Skip to content

Commit 29f2976

Browse files
cushonDagger Team
authored andcommitted
Document rationale for default cases per SwitchingProvider switch.
RELNOTES=n/a PiperOrigin-RevId: 967781839
1 parent 12cb0ca commit 29f2976

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

dagger-compiler/main/java/dagger/internal/codegen/compileroption/CompilerOptions.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,22 @@ public int keysPerComponentShard(XTypeElement component) {
145145
}
146146

147147
/**
148-
* Each switch size is fixed at 100 cases each and put in its own method. This is to limit the
149-
* size of the methods so that we don't reach the "huge" method size limit for Android that will
150-
* prevent it from being AOT compiled in some versions of Android (b/77652521). This generally
151-
* starts to happen around 1500 cases, but we are choosing 100 to be safe.
148+
* Each switch size is fixed at 100 cases each and put in its own method.
149+
*
150+
* <p>This balances trade-offs between compile-time / bytecode overhead and Android runtime AOT
151+
* compilation:
152+
*
153+
* <ul>
154+
* <li><b>Upper bound</b>: Large switch methods risk hitting the "huge" method size limit for
155+
* Android that prevents AOT compilation in some versions of Android (b/77652521, generally
156+
* around 1500 cases). Additionally, ART decides whether to AOT compile a method based on
157+
* whether the path is "hot" at runtime; keeping switch methods reasonably small ensures that
158+
* a single hot case does not force ART to compile a disproportionately large method and
159+
* consume extra runtime memory.
160+
* <li><b>Lower bound</b>: Making the number too small results in many small helper methods,
161+
* which increases classfile / bytecode size, constant pool overhead, DEX method count, and
162+
* javac attribution time (b/549228393).
163+
* </ul>
152164
*/
153165
// TODO(bcorso): Include a proguard_spec in the Dagger library to prevent inlining these methods?
154166
public int casesPerSwitchingProviderSwitch() {

0 commit comments

Comments
 (0)