Skip to content

Commit

Permalink
Remove abc inheritance from Serializable (#8254)
Browse files Browse the repository at this point in the history
Currently the Serializable class provides `serialize` and `deserialize` as `abstractmethod`s via the mechanisms afforded by inheritance from `abc.ABC`. Since this class is purely internal to `cudf` and is not describing an abstract interface in a manner useful to consumers of our code, the benefits of the abstract base class concept are outweighed by the performance and maintenance costs. In particular, `isinstance` checks on subclasses of `abc.ABC` are much more expensive than for normal classes (due to an expensive implementation of `__instancecheck__`), and (for better or worse) our code base currently makes use of these checks extensively. In addition, in certain places we can benefit from the use of custom metaclasses in `cudf`, but their usage becomes more cumbersome with `ABC` because metaclasses then also have to inherit from `ABCMeta` (which brings along any associated complexities). This PR removes that inheritance, replacing it with a much simpler approach that simply implements `serialize` and `deserialize` as raising `NotImplementedError`.

Authors:
  - Vyas Ramasubramani (https://github.com/vyasr)

Approvers:
  - Ashwin Srinath (https://github.com/shwina)
  - https://github.com/brandon-b-miller

URL: #8254
  • Loading branch information
vyasr authored May 20, 2021
1 parent 0ebf7e6 commit 7427049
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions python/cudf/cudf/core/abc.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Copyright (c) 2020-2021, NVIDIA CORPORATION.
"""Common abstract base classes for cudf."""

import abc
import sys
from abc import abstractmethod

import rmm

Expand All @@ -18,7 +16,7 @@
import pickle # type: ignore


class Serializable(abc.ABC):
class Serializable:
"""A serializable object composed of device memory buffers.
This base class defines a standard serialization protocol for objects
Expand All @@ -32,7 +30,6 @@ class Serializable(abc.ABC):
latter converts back from that representation into an equivalent object.
"""

@abstractmethod
def serialize(self):
"""Generate an equivalent serializable representation of an object.
Expand All @@ -53,10 +50,11 @@ def serialize(self):
:meta private:
"""
pass
raise NotImplementedError(
"Subclasses of Serializable must implement serialize"
)

@classmethod
@abstractmethod
def deserialize(cls, header, frames):
"""Generate an object from a serialized representation.
Expand All @@ -80,7 +78,9 @@ class can be constructed from a serialized representation generalized
:meta private:
"""
pass
raise NotImplementedError(
"Subclasses of Serializable must implement deserialize"
)

def device_serialize(self):
"""Serialize data and metadata associated with device memory.
Expand Down

0 comments on commit 7427049

Please sign in to comment.