Use Java reflection fast paths in Reflector for zero-arg constructors and property getters - #117
Merged
marcprux merged 2 commits intoSep 26, 2026
Conversation
… and property getters Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
marcprux
approved these changes
Sep 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to skiptools/skip-foundation#130 and skiptools/skip-android-bridge#33, chasing the same cost: the first kotlin-reflect touch in a process pays the full reflection-infrastructure init (descriptor deserialization,
KClassImplmember scans), which lands on the app's main thread during launch.With those two fixes shipped, the remaining launch-path entry into kotlin-reflect is the generated per-module
Bundle_Support.swift:which reaches
Reflector(reflectingClassName:arguments:)(constructor signature matching overKClass.constructors) andReflector.propertyValue(memberPropertiesscan) — both kotlin-reflect, for what is in practice a public zero-arg constructor and a plain getter. Any app that touchesBundle.modulebefore first frame (e.g. reading a localized string or a bundled resource inApplication.onCreate) pays this.This PR adds two
java.lang.reflectfast paths, falling back to the existing kotlin-reflect paths for everything else:Reflector(reflectingClassName:arguments:)with no arguments instantiates via a public zero-arg Java constructor when one exists. Kotlin constructors with default parameters compile to synthetic overloads with aDefaultConstructorMarkerparameter, so they don't match and fall through tomatchConstructoras before.propertyValuefirst resolves the property's JVM getter (getFoo()/isFoo()) viaClass.getMethodand invokes it directly. Java fields (which kotlin-reflect surfaces as properties) have no getter and fall through; non-public Kotlin members are excluded in practice by their module-mangled JVM getter names (getFoo$module). One behavioral nuance: a hypothetical Kotlin member whose getter is JVM-public under a clean name but notKVisibility.PUBLICwould now resolve where the old path threw — I couldn't construct such a case with kotlinc's current name mangling, but flagging it for review.Measured in the Polymarket app (Pixel 9 emulator, debug build, 12 cold starts,
am start -W): median TotalTime 1398ms → 1318ms, andskip.bridge.Reflectorframes disappear from the simpleperf startup trace entirely (kotlin-reflect residual drops ~10×, the remainder coming from other libraries).