Commit bb09ef80
bb09ef809ab3Merged
Yasuhiro Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified
Description
perf: hoist infer_type(recv) once at top of infer_operator_type
Each branch (+, -, *, /, <<, -@) recomputed lt = infer_type(recv)
on top of the unconditional bigint-check call. Because infer_type recurses
into infer_call_type -> infer_operator_type, the duplicated call doubled
the work at every level, producing exponential blow-up on deep call chains.
Compute lt once when recv >= 0 and reuse it everywhere. Output is
byte-identical for build/codegen.ast; runtime drops from ~2:15 to ~0:18
(~7x faster).
Details
- Commit
- bb09ef809ab3
- Parent
- 0f883a24539a
spinel_codegen.rbmodifiedView file
@@ -1457,9 +1457,11 @@
14571457
end14581458
14591459
def infer_operator_type(nid, mname, recv)1460-
# Bigint operators return bigint1460+
# Receiver type is consulted by nearly every branch below; compute once.1461+
lt = ""14611462
if recv >= 014621463
lt = infer_type(recv)1464+
# Bigint operators return bigint14631465
if lt == "bigint"14641466
if mname == "+" || mname == "-" || mname == "*" || mname == "/" || mname == "%"14651467
return "bigint"@@ -1477,7 +1479,6 @@
14771479
end14781480
if mname == "+"14791481
if recv >= 01480-
lt = infer_type(recv)14811482
if lt == "string"14821483
return "string"14831484
end@@ -1509,7 +1510,6 @@
15091510
end15101511
if mname == "-"15111512
if recv >= 01512-
lt = infer_type(recv)15131513
if lt == "float"15141514
return "float"15151515
end@@ -1529,7 +1529,6 @@
15291529
end15301530
if mname == "*"15311531
if recv >= 01532-
lt = infer_type(recv)15331532
if lt == "float"15341533
return "float"15351534
end@@ -1555,7 +1554,6 @@
15551554
end15561555
if mname == "/"15571556
if recv >= 01558-
lt = infer_type(recv)15591557
if lt == "float"15601558
return "float"15611559
end@@ -1578,7 +1576,6 @@
15781576
end15791577
if mname == "<<"15801578
if recv >= 01581-
lt = infer_type(recv)15821579
if lt == "mutable_str"15831580
return "mutable_str"15841581
end@@ -1590,7 +1587,7 @@
15901587
end15911588
if mname == "-@"15921589
if recv >= 01593-
return infer_type(recv)1590+
return lt15941591
end15951592
return "int"15961593
end