jfhbrook / pyee

A rough port of Node.js's EventEmitter to Python with a few tricks of its own
https://github.com/jfhbrook/public
MIT License
371 stars 39 forks source link

Slight memory optimizations #33

Closed LivInTheLookingGlass closed 7 years ago

LivInTheLookingGlass commented 7 years ago

Adding __slots__ allows python to know in advance what attributes your class will have. This means it can specifically allocate only those names. This means access is slightly faster, and you allocate less memory per instance of the objects

jfhbrook commented 7 years ago

On the face of it this sounds reasonable, though lemme research slots myself just to confirm that this is a good idea.

I can probably get this and #32 merged/released tonight or maybe tomorrow.

jfhbrook commented 7 years ago

Alright, I did some digging and I'm going to close this PR. Like I'm glad you made the suggestion, but because this breaks assignment of arbitrary attrs this would be a breaking change for only slight memory gains.

I'm going to at least wait until someone has a use case where they can show that this makes a difference.

I'll take #32 though.

LivInTheLookingGlass commented 7 years ago

Okay, fair enough. Thank you for reviewing. I appreciate you taking the time.

On February 7, 2017 9:17:13 PM EST, Joshua Holbrook notifications@github.com wrote:

Alright, I did some digging and I'm going to close this PR. Like I'm glad you made the suggestion, but because this breaks assignment of arbitrary attrs this would be a breaking change for only slight memory gains.

I'm going to at least wait until someone has a use case where they can show that this makes a difference.

I'll take #32 though.

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/jfhbrook/pyee/pull/33#issuecomment-278209118

jfhbrook commented 7 years ago

Yeah no sweat! I like getting code submissions, especially on this project!