Skip to content

gh-159186: Skip branch-history recording in builds without Tier 2 - #159187

Open
lgeiger wants to merge 1 commit into
python:mainfrom
lgeiger:record-branch-tier-2
Open

lgeiger wants to merge 1 commit into
python:mainfrom
lgeiger:record-branch-tier-2

Conversation

@lgeiger

@lgeiger lgeiger commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

As far as I can tell, branch history is consumed only if Tier 2 interpreter is enabled. This disables branch history recording for builds without Tier 2 which saves a few instructions for the POP_JUMP_IF_{TRUE,FALSE} op codes.

A toy benchmarks on macOS with ./configure --enable-optimizations --with-lto=full --with-tail-call-interp shows a tiny improvement but its very small so this might be noise. In any case, I don't see any downsides to this, so opening the PR even if performance improvement will be minimal.

Benchmark Baseline Candidate pyperf result
Alternating true/false 4.37 ns 4.15 ns 1.05× faster
Shuffled true/false 7.42 ns 7.64 ns 1.03× slower
Always true 4.81 ns 4.61 ns 1.04× faster
Always false 4.73 ns 4.64 ns 1.02× faster
No-branch control 3.18 ns 3.25 ns 1.02× slower
def branch_loop(values):
    result = 0
    for value in values:
        if value:
            result = 1
        else:
            result = 2
    return result


def control_loop(values):
    result = 0
    for value in values:
        result = 1
    return result


if __name__ == "__main__":
    import random
    import pyperf

    runner = pyperf.Runner()
    size = 10000
    mixed_shuffled = [True, False] * (size // 2)
    random.Random(0).shuffle(mixed_shuffled)
    runner.bench_func("branch_mixed", branch_loop, [True, False] * (size // 2), inner_loops=size)
    runner.bench_func("branch_mixed_shuffled", branch_loop, mixed_shuffled, inner_loops=size)
    runner.bench_func("branch_all_true", branch_loop, [True] * size, inner_loops=size)
    runner.bench_func("branch_all_false", branch_loop, [False] * size, inner_loops=size)
    runner.bench_func("no_branch_control", control_loop, mixed_shuffled, inner_loops=size)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant