Skip to content

Define __slots__ for small classes#40783

Merged
tensorflow-copybara merged 2 commits intotensorflow:masterfrom
lgeiger:slots
Jul 9, 2020
Merged

Define __slots__ for small classes#40783
tensorflow-copybara merged 2 commits intotensorflow:masterfrom
lgeiger:slots

Conversation

@lgeiger
Copy link
Copy Markdown
Contributor

@lgeiger lgeiger commented Jun 25, 2020

TensorFlow has many small classes that are used internally as wrappers or containers. Frequently used objects can benefit from defining __slots__.

From the Python docs:

__slots__ allow us to explicitly declare data members (like properties) and deny the creation of __dict__ and __weakref__ (unless explicitly declared in __slots__ or available in a parent.)
The space saved over using __dict__ can be significant. Attribute lookup speed can be significantly improved as well.

This PR explicitely defines __slots__ for a non exhaustive list of classes that have very few attributes, tend not to be inherited from and don't use dynamic assignment of new variables.

@google-ml-butler google-ml-butler bot added the size:M CL Change Size: Medium label Jun 25, 2020
@gbaned gbaned self-assigned this Jun 25, 2020
alextp
alextp previously approved these changes Jun 25, 2020
@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Jun 25, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Jun 25, 2020
@google-ml-butler google-ml-butler bot removed the ready to pull PR ready for merge process label Jun 25, 2020
@lgeiger lgeiger requested a review from alextp June 25, 2020 21:44
alextp
alextp previously approved these changes Jun 25, 2020
@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Jun 25, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Jun 25, 2020
@google-ml-butler google-ml-butler bot removed the ready to pull PR ready for merge process label Jun 25, 2020
@lgeiger lgeiger requested a review from alextp June 25, 2020 22:28
alextp
alextp previously approved these changes Jun 25, 2020
@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Jun 25, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Jun 25, 2020
@google-ml-butler google-ml-butler bot removed the ready to pull PR ready for merge process label Jun 25, 2020
@lgeiger
Copy link
Copy Markdown
Contributor Author

lgeiger commented Jun 25, 2020

Sorry about the failing tests (it's a bit challenging to run all test locally without a proper bazel cache) af273bc should fix it.

@lgeiger lgeiger requested a review from alextp June 25, 2020 23:42
alextp
alextp previously approved these changes Jun 25, 2020
@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Jun 25, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Jun 25, 2020
@lgeiger lgeiger requested a review from alextp June 26, 2020 10:58
@google-ml-butler google-ml-butler bot removed the ready to pull PR ready for merge process label Jun 26, 2020
alextp
alextp previously approved these changes Jun 26, 2020
@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Jun 26, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Jun 26, 2020
@lgeiger
Copy link
Copy Markdown
Contributor Author

lgeiger commented Jun 28, 2020

aa41fec should fix the last CI breakage, sorry about that.

@lgeiger lgeiger requested a review from alextp June 28, 2020 16:48
@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Jun 29, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Jun 29, 2020
@tensorflow-copybara tensorflow-copybara merged commit 61a985b into tensorflow:master Jul 9, 2020
@lgeiger lgeiger deleted the slots branch July 9, 2020 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes ready to pull PR ready for merge process size:M CL Change Size: Medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants