← Back to Pull requests

Compiler: Skip the union-split subtype query for fully covering matches #65251

Merged
KristofferC merged 1 files (2 lines) on Nov 25, 2026 18:11 UTC
View on GitHub
KristofferC KristofferC commented on Nov 25, 2026 13:58 UTC
Author

This saves 1.6% of the instructions of type inference and optimization for the methods the Ferrite TTFX task compiles.

Assisted-by: Claude Code (Claude Fable 5.2)

Diff: 2 lines (+1 / -1) across 1 files Reviewer: topolarity Review duration: 252m
All Vouch review confidence checks passed
Residual risk 0.04 = Change Risk (0.15) × (1 − Review Confidence (0.72)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.15 · 2 lines diff across 1 files
0.15
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.56 · 4 substantive comment(s)
0.56
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
72%
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.066
Ai Authored ai_authored
0.050
Real PR Conversation Timeline
7 items
topolarity topolarity approved these changes on Nov 25, 2026 15:02 UTC
Approved Reviewer

Approved these changes.

vtjnash vtjnash approved these changes on Nov 25, 2026 18:11 UTC
Approved Reviewer

Approved these changes.

vtjnash vtjnash commented on Nov 25, 2026 18:11 UTC
Contributor

Somewhat unbelievable that an pointer equality comparison could be 1.6% of the instructions, but sure

KristofferC KristofferC commented on Nov 25, 2026 18:23 UTC
Author

Are you saying that the subtype check there is always a pointer equality comparison? Will look into that, because it means my instruction measuring setup must be completely wrong.

KristofferC KristofferC commented on Nov 25, 2026 18:29 UTC
Author

So when I instrument the call you are talking about I get that 10,519 of 75,421 queries are resolved by a pointer equality check. Here are some queries that are not (which are executed in the workload I measured on):

┌───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬────────────┐
│ Count │                                                       Query                                                       │ Instr each │
├───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────┤
│ 1275  │ Tuple{typeof(==), Int64, Int64} <: Tuple{typeof(==), T, T} where T<:Number                                        │ 3541       │
├───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────┤
│ 979   │ Tuple{typeof(>), Int64, Int64} <: Tuple{typeof(>), Any, Any}                                                      │ 572        │
├───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────┤
│ 973   │ Tuple{typeof(<=), Int64, Int64} <: Tuple{typeof(<=), T, T} where T<:Union{Int128, Int16, Int32, Int64, Int8}      │ 3232       │
├───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────┤
│ 617   │ Tuple{Core.TypeEgal{Int64}, Int64} <: Tuple{Type{Int64}, Union{Bool, Int128, …, UInt8}}                           │ 6245       │
├───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────┤
│ 601   │ Tuple{typeof(iterate), UnitRange{Int64}, Int64} <: Tuple{typeof(iterate), OrdinalRange{T}, Any} where T           │ 4773       │
├───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────┤
│ 490   │ Tuple{typeof(iterate), UnitRange{Int64}} <: Tuple{typeof(iterate), OrdinalRange}                                  │ 4596       │
├───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────┤
│ 354   │ Tuple{typeof(getindex), Vector{Int64}, Int64} <: Tuple{typeof(getindex), Array, Int64}                            │ 6020       │
├───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────┤
│ 192   │ Tuple{typeof(getindex), Memory{UInt8}, Int64} <: Tuple{typeof(getindex), GenericMemory, Int64}                    │ 8917       │
├───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────┤
│ 94    │ Tuple{Core.TypeEgal{NamedTuple{(:sizehint,)}}, Tuple{Int64}} <: Tuple{Type{NamedTuple{names}}, Tuple} where names │ 21193      │
└───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴────────────┘

---

Tallying up things (for covering queries):

┌──────────────────────────────────┬──────────────────┬─────────────────┬───────────────┐
│              Shape               │ Share of queries │ Avg instr/query │ Share of cost │
├──────────────────────────────────┼──────────────────┼─────────────────┼───────────────┤
│ Pointer-equal                    │ 14.0%            │ 108             │ 0.4%          │
├──────────────────────────────────┼──────────────────┼─────────────────┼───────────────┤
│ Sig is a DataType, not identical │ 62.3%            │ 3642            │ 63.0%         │
├──────────────────────────────────┼──────────────────┼─────────────────┼───────────────┤
│ Sig is a UnionAll                │ 23.7%            │ 5554            │ 36.5%         │
└──────────────────────────────────┴──────────────────┴─────────────────┴───────────────┘

Replaying the subtype checks for all of these cost 272M instructions, which is 1.05% of the workload's 25.9G.

vtjnash vtjnash commented on Dec 02, 2026 22:47 UTC
Contributor

I was just re-stating what the robot said in the commit message:

A match that fully covers the call has the call signature itself as its spec_types

I wasn't entirely sure how we ended up with getting something out of there (which is the type-intersect walker closure->ti = jl_type_intersection_env_s(closure->type, (jl_value_t*)ml->sig, penv, &closure->issubty)) with closure->ti !== ml->sig, but it looks like the algorithm prefers to return closure->type (type a), even that will likely still cost us this this 1.6% in quite many other places too. We might want to revert this and fix it properly, since it might imply fixing properly would speed up reinfer performance by several %.

Reviewers
Assignees
KristofferC KristofferC
Labels
risk: low confidence: 72.3% 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: 14.6% (LOW) · Higher = larger blast radius
14.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: 72.3% · Lower = rushed or shallow review
72.3%
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: 4% · Safe to merge
4%