Skip to content

JIT code has too many validity checks #131726

@brandtbucher

Description

@brandtbucher

We currently remove _CHECK_VALIDITY ops as part of a final linear pass over JIT code, with the heuristic being:

  • If any op escaped since the last validity check, leave it in.
  • Otherwise, remove it.

However, this is too strict. A looser, still correct heuristic would be:

  • If any op escaped since the last validity check, and we have an optimization that relies on that validity before the next validity check, leave it in.
  • Otherwise, remove it.

As a simple example: _POP_TOP escapes. If we have two POP_TOP instructions in a row, the JIT will check validity between them, which isn't necessary.

Since it's our optimizations that create a reliance on validity checks, the removal of validity checks and the tracking of validity should be done as part of the abstract interpretation. If could be as simple as calling require_validity(ctx); whenever we perform a validity-requiring optimization. This helper would just re-insert the last seen _CHECK_VALIDITY instruction.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedperformancePerformance or resource usagetopic-JIT

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions