Skip to content

Optimize float operations by mutating uniquely-referenced operands in place (JIT only) #146306

Description

@eendebakpt

Feature or enhancement

Proposal:

When the tier 2 optimizer can prove that an operand to a float binary operation is uniquely referenced, we can mutate it in place instead of allocating a new PyFloatObject. This avoids a PyFloat_FromDouble allocation and the subsequent deallocation of the consumed operand on every iteration.

The unique reference tracking infrastructure added in #144300 can be used for the float operations as well. Also see #90530 where a similar optimization was proposed for tier 1 using runtime refcount checks.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. added a commit that references this issue on Mar 22, 2026
  2. added a commit that references this issue on Mar 24, 2026
  3. Fidget-Spinner commented on Mar 24, 2026

    @Fidget-Spinner
    Member

    I think the remaining float operations are probably rare and also annoying to account for (e.g. float OP int), so let's consider this done, and expand on it in future issues if need be.

    The next big thing is probably compact longs.

  4. added 6 commits that reference this issue on Mar 24, 2026
  5. added a commit that references this issue on Apr 16, 2026
  6. 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 usagetopic-JITtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions