← Back to Pull requests

Compare bridged struct and class peers by pointer in generated equals #292

Closed
unknown closed this pull request without merging on Oct 11, 2026 18:30 UTC
View on GitHub
unknown unknown commented on Oct 07, 2026 10:20 UTC
Author

Summary

For bridged structs and classes, the generated Kotlin equals/== passed the two Kotlin objects to Swift_isequal, and the Swift side called fromJavaObject on each, which reads Swift_peer through a JNI call back into Java per operand. Compose calls equals on every element when it compares a List of bridged values in changed(), 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 (both SwiftObjectPointer), and Swift reads the values straight from the pointers:

override fun equals(other: Any?): Boolean {
    if (other === this) return true
    if (other !is S) return false
    return Swift_isequal(Swift_peer, other.Swift_peer)
}

public func S_Swift_isequal(_ Java_env: JNIEnvPointer, _ Java_target: JavaObjectPointer, _ lhs: SwiftObjectPointer, _ rhs: SwiftObjectPointer) -> Bool {
    let lhs_swift: SwiftValueTypeBox<S> = lhs.pointee()!
    let rhs_swift: SwiftValueTypeBox<S> = rhs.pointee()!
    return lhs_swift.value == rhs_swift.value
}

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 a Double.nan.

Numbers

| | Pixel stock | Pixel patched | | Mac stock | Mac patched | |
|---|---|---|---|---|---|---|
| [Struct] == [Struct], 200 elements (Compose changed()) | 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). ChatMessage mirrors a production chat message: 13 fields including a nested 10-field user struct, Dates, an enum with associated values and arrays of nested structs. FeedRowID is 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 bridged BenchModel from the transpiled Kotlin test: scalar, String, struct and 200-element array getters, plus == on two 200-element [Struct] lists (what Compose's changed() does). Each row is the best of 15 trials, two interleaved stock/patched rounds.

  • Device: Pixel 10 Pro Fold, Android 17, connectedAndroidTest with testBuildType = "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.

  • Mac: the same test under Robolectric, Swift built with -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 two BridgeToKotlinTests expectations updated for the new output.

  • skip-bridge skip test against this skipstone (SKIPLOCAL): 153/153, including testSwiftClassEquatable / testSwiftClassHashable, which go through the new code.

  • Polymarket's Android app builds with it (assembleDebug); all 425 generated equals sites 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

    Diff: 460 lines (+345 / -115) across 5 files Reviewer: marcprux Review duration: 6250m
    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
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.6% (MEDIUM) · Higher = larger blast radius
    45.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.0% · Safe to merge
    18.0%