Compare bridged struct and class peers by pointer in generated equals #292
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 460 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.367
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #292"
general
weight: 0.35
marcprux
Summary
For bridged structs and classes, the generated Kotlin
equals/==passed the two Kotlin objects toSwift_isequal, and the Swift side calledfromJavaObjecton each, which readsSwift_peerthrough a JNI call back into Java per operand. Compose callsequalson every element when it compares aListof bridged values inchanged(), so a 200-row list paid 200 Kotlin → Swift calls plus 400 Swift → Java calls per comparison.Now Kotlin passes
Swift_peer/other.Swift_peer(bothSwiftObjectPointer), and Swift reads the values straight from the pointers:Classes use
let lhs_swift: C = lhs.pointee()!. Generic types, enums and sealed-class enums keep the existing generated code. There is deliberately no pointer-equality shortcut on the Swift side, so==keeps its semantics for types like structs holding aDouble.nan.Numbers
| | Pixel stock | Pixel patched | | Mac stock | Mac patched | |
|---|---|---|---|---|---|---|
|
[Struct] == [Struct], 200 elements (Composechanged()) | 426 µs | 262 µs | 1.63× | 224 µs | 113 µs | 1.98× |App-shaped types (Pixel only; the rows above use a deliberately small 4-field struct).
ChatMessagemirrors a production chat message: 13 fields including a nested 10-field user struct,Dates, an enum with associated values and arrays of nested structs.FeedRowIDis a String-raw enum plus a String key.| | Pixel stock | Pixel patched | |
|---|---|---|---|
|
[ChatMessage] == [ChatMessage], 50 elements | 164 µs | 121 µs | 1.36× ||
[FeedRowID] == [FeedRowID], 200 elements | 376 µs | 244 µs | 1.54× |The saving per element is constant (two calls back into Java), so it is a smaller share for types whose Swift
==compares many fields.How this was measured
A benchmark test in
SkipBridgeToKotlinSamplesTests(not part of these PRs) reads a bridgedBenchModelfrom the transpiled Kotlin test: scalar,String, struct and 200-element array getters, plus==on two 200-element[Struct]lists (what Compose'schanged()does). Each row is the best of 15 trials, two interleaved stock/patched rounds.connectedAndroidTestwithtestBuildType = "release". The debug test APK is debuggable, so ART turns on CheckJNI ("Late-enabling -Xcheck:jni"), which roughly doubled every JNI cost and would have overstated these changes.-O.Rows these changes don't touch moved by up to ±12% between rounds on the device; treat that as the noise floor.
Tests
swift test --filter SkipSyntaxTests: 867/867, with the twoBridgeToKotlinTestsexpectations updated for the new output.skip testagainst this skipstone (SKIPLOCAL): 153/153, includingtestSwiftClassEquatable/testSwiftClassHashable, which go through the new code.assembleDebug); all 425 generatedequalssites use the new form.Related: skiptools/swift-jni#11, skiptools/skip-bridge#122, skiptools/skipstone#293 (independent; each can land on its own)
🤖 Generated with Claude Code