Commit f5371fa7
f5371fa7b865Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified
Description
perf: early-exit iterative type inference when fixed point reached
The iterative loop that refines return / ivar / param types ran a fixed 4 iterations. In practice most programs converge after 1-2. Capture a string fingerprint of the three refined arrays each iteration and break as soon as it stops changing.
Self-host compile of spinel_codegen.rb: 78 s -> 67 s (-14%). Full bootstrap: 5:59 -> 5:14 (-13%). Cumulative since baseline 6:19: -17%.
74 tests / 55 benchmarks pass. gen2.c == gen3.c.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- f5371fa7b865
- Parent
- 22cb8b0286a5
spinel_codegen.rbmodifiedView file
@@ -7132,18 +7132,32 @@
71327132
end71337133
end71347134
7135+
# Build a string fingerprint of the arrays that iterative type inference7136+
# refines. Identical fingerprints between successive iterations means a7137+
# fixed point has been reached and further iterations are wasted work.7138+
def inference_signature7139+
@meth_return_types.join("|") + "/" + @cls_ivar_types.join("|") + "/" + @meth_param_types.join("|")7140+
end7141+
71357142
def compile71367143
collect_all71377144
infer_main_call_types71387145
infer_function_body_call_types71397146
infer_class_body_call_types71407147
detect_poly_locals7141-
# Iterative type inference: converge param types, return types, ivar types7148+
# Iterative type inference: converge param types, return types, ivar types.7149+
# Stop early when the signature of these three arrays stops changing.71427150
iter = 07151+
prev_sig = inference_signature71437152
while iter < 471447153
infer_all_returns71457154
infer_ivar_types_from_writers71467155
detect_poly_params7156+
cur_sig = inference_signature7157+
if cur_sig == prev_sig7158+
break7159+
end7160+
prev_sig = cur_sig71477161
iter = iter + 171487162
end71497163
# Fix nil/poly-typed ivars with attr_writer to nullable self type