Skip to content

Commit df86d68

Browse files
committed
perf(jit): retain managed baseline loops (#444)
1 parent 4c0d04b commit df86d68

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/vm.zig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5172,6 +5172,13 @@ pub fn run(vm: *Interpreter, chunk: *Chunk, frame: ?*Frame) EvalError!Value {
51725172
}
51735173

51745174
fn loadOrCompileOptimizer(owner: *jit.Owner, chunk: *Chunk) ?*const jit.CompiledCode {
5175+
// A managed baseline artifact already owns the whole loop, including exact
5176+
// checkpoint accounting. The generic optimizer region currently expands
5177+
// the same loop into finer-grained guarded operations and can be much
5178+
// slower; do not replace a proven whole-loop tier merely because the later
5179+
// profiling threshold was crossed. Effect/property chunks that baseline
5180+
// cannot compile still reach the optimizer normally.
5181+
if (chunk.tier.loadCode()) |baseline| if (baseline.manages_steps) return null;
51755182
var artifact = chunk.optimizer_tier.loadArtifact(jit.CompiledCode);
51765183
if (artifact == null) if (owner.claimOptimizerCompilation(
51775184
&chunk.optimizer_tier,
@@ -11773,6 +11780,12 @@ test "vm: numeric baseline tier preserves steps and non-number fallback" {
1177311780
}
1177411781
try std.testing.expectEqual(jit.TierState.ready, sum_chunk.tier.loadState());
1177511782
try std.testing.expect(sum_chunk.tier.loadCode().?.manages_steps);
11783+
for (0..12) |_| {
11784+
sum_slots = .{ Value.num(10), Value.undef(), Value.undef() };
11785+
try std.testing.expectEqual(@as(f64, 45), (try run(&machine, sum_chunk, &sum_frame)).asNum());
11786+
}
11787+
try std.testing.expectEqual(@as(u64, 0), sum_chunk.optimizer_tier.compileCount());
11788+
try std.testing.expect(sum_chunk.optimizer_tier.loadArtifact(jit.CompiledCode) == null);
1177611789

1177711790
const add_chunk = root.fns.items[1].chunk.?;
1177811791
var add_slots = [_]Value{Value.num(0)};

0 commit comments

Comments
 (0)