Skip to content

PERF: __slots__ not declared consistently, negating some memory savings #45124

Closed

Description

@ariebovenberg

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this issue exists on the latest version of pandas.

  • I have confirmed this issue exists on the master branch of pandas.

Reproducible Example

👋 Hello there!

I've found quite some classes declaring __slots__ whose bases classes do not. This negates some of the performance benefits. Fixing this should be a relatively easy performance win.

After some experimentation I've found it's not quite as easy as adding __slots__ = () to the bases classes. But, it should still be relatively simple.

List of affected classes I could find:

pandas.core.internals.array_manager.BaseArrayManager
pandas.core.internals.array_manager.SingleArrayManager
pandas.core.internals.blocks.Block
pandas.core.internals.blocks.CategoricalBlock
pandas.core.internals.blocks.DatetimeLikeBlock
pandas.core.internals.blocks.NumericBlock
pandas.core.internals.blocks.ObjectBlock
pandas.core.internals.managers.BaseBlockManager
pandas.core.internals.managers.SingleBlockManager

Installed Versions

n/a

Prior Performance

No response

Activity

  1. added
    Needs TriageIssue that has not been reviewed by a pandas team member
    PerformanceMemory or execution speed performance
    on Dec 30, 2021
  2. ariebovenberg commented on Dec 30, 2021

    @ariebovenberg
    Author

    take

  3. removed
    Needs TriageIssue that has not been reviewed by a pandas team member
    on Jan 13, 2022
  4. jbrockmendel commented on Mar 22, 2026

    @jbrockmendel
    Member

    I'm skeptical this is worth the bother.

  5. ariebovenberg commented on Mar 22, 2026

    @ariebovenberg
    Author

    @jbrockmendel you're probably right.

    Since posting this issue I've done a deep investigation of __slots__ benefits. I even presented a talk at EuroPython about it.

    The tl;dw is:

    • On python 3.11+, slots savings are reduced (regular objects got a lot more performant)
    • In an inheritance tree, either use __slots__ everywhere, or not at all. Mixing __slots__ and non-__slots__ classes through inheritance can lead to performance issues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Closing CandidateMay be closeable, needs more eyeballsPerformanceMemory or execution speed performance

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions