-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
Optimize frozenset construction #150027
Copy link
Copy link
Open
Labels
performancePerformance or resource usagePerformance or resource usagesprinttype-featureA feature request or enhancementA feature request or enhancement
Metadata
Metadata
Assignees
Labels
performancePerformance or resource usagePerformance or resource usagesprinttype-featureA feature request or enhancementA feature request or enhancement
Fields
Give feedbackNo fields configured for issues without a type.
Projects
Status
Todo
Feature or enhancement
Proposal:
Many cases of
frozensetlook like this:Currently, this constructs a new frozenset and copies the set object created by the literal. We can optimize this by detecting that it's a set literal via
PyUnstable_Object_IsUniqueReferencedTemporary, and then simply move the mutableset's memory into thefrozensetwithout a copy.Additionally, we have some optimizations for generator expressions inside sets. For example, this will be optimized by the compiler into some bytecode magic:
We can extend this optimization to
frozensets as well.Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
frozensetobjects #150028