Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PERF: Fix performance regression due to CoW ref tracking #51390

Merged
merged 2 commits into from
Feb 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pandas/_libs/internals.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -874,10 +874,10 @@ cdef class BlockValuesRefs:
data.
"""
cdef:
public object referenced_blocks
public list referenced_blocks

def __cinit__(self, blk: SharedBlock) -> None:
self.referenced_blocks = weakref.WeakSet([blk])
self.referenced_blocks = [weakref.ref(blk)]

def add_reference(self, blk: SharedBlock) -> None:
"""Adds a new reference to our reference collection.
Expand All @@ -887,7 +887,7 @@ cdef class BlockValuesRefs:
blk: SharedBlock
The block that the new references should point to.
"""
self.referenced_blocks.add(blk)
self.referenced_blocks.append(weakref.ref(blk))

def has_reference(self) -> bool:
"""Checks if block has foreign references.
Expand All @@ -899,5 +899,8 @@ cdef class BlockValuesRefs:
-------
bool
"""
self.referenced_blocks = [
ref for ref in self.referenced_blocks if ref() is not None
lithomas1 marked this conversation as resolved.
Show resolved Hide resolved
]
# Checking for more references than block pointing to itself
return len(self.referenced_blocks) > 1