Skip to content

Optimize new uops added for trace recording #144651

Closed

Description

@markshannon

#144179 added recording of values to the trace recorder.
It also fixed some correctness issues around calls and returns (and sends and yields), but the optimizer hasn't caught up, resulting in a performance drop.

To fix that we need to:

  • optimize away the new guards, using function and code watchers.
  • convert recorded functions and guarded code/function values into known constants in the optimizer
  • Likewise for recorded code objects

Linked PRs

Activity

  1. added
    type-featureA feature request or enhancement
    performancePerformance or resource usage
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    on Feb 10, 2026
  2. Kaushalt2004 commented on Feb 10, 2026

    @Kaushalt2004
    Contributor

    I would Like to make a review for this

  3. Fidget-Spinner commented on Feb 10, 2026

    @Fidget-Spinner
    Member

    @Kaushalt2004 sorry but could you please stop spamming issues claiming you would like to make a review? If you want to make a review, you can always just leave a review on the PR. There is no need to say you want to review on the issue.

  4. Fidget-Spinner commented on Feb 10, 2026

    @Fidget-Spinner
    Member

    Now that I think about it a bit more, why do we need _GUARD_CODE again? Unless I'm mistaken, the only way we can change the code version is if the code object itself changes. Aren't code versions basically immutable once set?

    So we should only need a function watcher, not a code watcher? After all, bytecode instrumentation triggers executor invalidation too.

  5. markshannon commented on Feb 11, 2026

    @markshannon
    MemberAuthor

    We need _GUARD_CODE to check that execution is following the same path as the one we recorded.

  6. Fidget-Spinner commented on Feb 11, 2026

    @Fidget-Spinner
    Member

    We need _GUARD_CODE to check that execution is following the same path as the one we recorded.

    Isn't that the point of _GUARD_IP?

  7. markshannon commented on Feb 11, 2026

    @markshannon
    MemberAuthor

    The _GUARD_IP uops check the instruction pointer is the same, not the code object.
    The code object could either have been deleted and replaced by another at the same location, or (more likely) been instrumented.
    There may be some redundancy, but that's fine as the optimizer will removed it (once I've implemented that).

  8. added a commit that references this issue on Feb 19, 2026
  9. added a commit that references this issue on Feb 28, 2026
  10. Fidget-Spinner commented on Mar 13, 2026

    @Fidget-Spinner
    Member

    This introduced a bug #144414 (comment)

  11. markshannon commented on Mar 16, 2026

    @markshannon
    MemberAuthor

    Fixed. #146018 for optimizing _GUARD_CODE_VERSION specifically.

  12. added a commit that references this issue on Apr 25, 2026
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

    interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions