Skip to content

TypedPython: compiled code never checks the eval breaker (signals, GC, GIL hand-off) #141

Closed

Description

@b-re-w

Since N-8, compiled loops do not check the eval breaker, so during a long compiled loop four things are deferred until it returns: signals (KeyboardInterrupt), scheduled garbage collections, pending calls, and dropping the GIL for other threads. The first three only move in time. The last starves other Python threads, which is a behaviour difference, not only a timing one.

Proposal: check the eval breaker at loop back-edges and at calls, with a cost measurement (nbody, spectral-norm, fannkuch) before and after. Design note: docs/design/typedpython.md §4.3.4 마.2 (PR for N-12).

Done when: a test shows a second Python thread makes progress while a compiled loop runs, KeyboardInterrupt reaches a compiled loop, and the measured cost is recorded.

Activity

  1. b-re-w commented on Oct 3, 2026

    @b-re-w
    MemberAuthor

    Phase 1 (feat/tp-eval-breaker) cost, interleaved A/B against develop in a quiet window (load 2.2 to 3.0), 11 pairs:

    after / before, median range
    fannkuch-redux 1.109 1.045 to 1.135
    nbody 1.005 0.975 to 1.036
    • The first version, which decremented a module-global countdown in every loop iteration, cost fannkuch about 38%. Switching to a function-local countdown brought that down to about 11%.
    • nbody is unaffected, as expected: its loops are in functions holding array snapshots, which do not poll.
    • 11% is still too much for fannkuch's short inner while loops. Next: poll only at the back-edges of loops that are not innermost, plus innermost loops by strip-mining (a chunked inner loop with one poll per chunk), then re-measure.
    • Not landing until then.

    Follow-ups:

  2. b-re-w commented on Oct 17, 2026

    @b-re-w
    MemberAuthor

    Landed in develop via #207. Measured cost: fannkuch +8.2% (accepted, see the PR); chunked range-loop polling is #206; phase 2 is in #159.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions