Skip to content

complex() constructor bypasses the existing freelist #162428

Closed

Description

@cmaloney

Feature or enhancement

complex has a freelist but complex(...) always allocates through complex_subtype_from_c_complex() which misses it.

a = 1.5; z = 1j
x = z * z; i = id(x); del x
id(complex(a, a)) == i   # False on main

Using PyComplex_FromCComplex() for exact complex, as float_new_impl() does with PyFloat_FromDouble(), makes exact complex(...) calls 1.12x-1.29x faster in microbenchmarks; subclasses are unchanged.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. self-assigned this
    on Nov 22, 2026
  2. added
    type-featureA feature request or enhancement
    performancePerformance or resource usage
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    on Nov 22, 2026
  3. changed the title [-]complex() constructor results bypass the complex freelist[/-] [+]complex() constructor bypasses the existing freelist[/+] on Nov 22, 2026
  4. added a commit that references this issue on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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