Coder Social home page Coder Social logo

Comments (8)

Gobot1234 avatar Gobot1234 commented on May 20, 2024

Gonna give this one a shot 👍

from python-betterproto.

Gobot1234 avatar Gobot1234 commented on May 20, 2024
>>> @dataclass
... class Data:
...     t: int
...     m: str
...     n: float
... 
>>> Data(t=3, m=3, n=3).__sizeof__()
32
>>> @dataslots.with_slots
... @dataclass
... class Data:
...     t: int
...     m: str
...     n: float
... 
>>> Data(t=3, m=3, n=3).__sizeof__()
40

Really not seeing much in the ways of benefits here.

Attribute access is marginally faster as is instantiation but this doesn't seem like a worthwhile trade off against the extra overhead and memory size.

I might be seriously missing something or it might be Python 3.9 doing stuff not too sure though.

from python-betterproto.

nat-n avatar nat-n commented on May 20, 2024

I'm curious did you find a measurable speed improvement?
Is the memory penalty constant or proportional to the number of fields? (or does it turn to a benefit with enough fields?)

Admittedly I've not done enough investigation to validate this, but my thinking was the if the technique from dataslots were implemented directly in the Message class then it should give the most benefit.

from python-betterproto.

Gobot1234 avatar Gobot1234 commented on May 20, 2024

The there didn't appear to be a point at which the un-slotted class used more memory. The speed improvement wasn't noteworthy. Might have to test some more however.

from python-betterproto.

Gobot1234 avatar Gobot1234 commented on May 20, 2024

Actually I take this back it appears to be working now 🤔

from python-betterproto.

Gobot1234 avatar Gobot1234 commented on May 20, 2024

All tests were ran with timeit.repeat and a sped up custom implementation of dataslots.

So for a single slotted class attribute access 0.11287586920000003s vs unslotted 0.1498976172s

Init appears to be slightly slower slotted 25.6038842112s vs 22.337924385599997s.

Overhead is relatively low at 3.2458480566e-05s per class per decorator directly using the implementation of the above library finishes in 3.7460388750999996e-05s

Memory usage temperamental which I think is caused by the use of betterproto.int32_field(0) etc. So I think it's safe to say the previous statements still apply,

from python-betterproto.

Gobot1234 avatar Gobot1234 commented on May 20, 2024

The size issues might be due to using it on instances this sure is very strange.

from python-betterproto.

Gobot1234 avatar Gobot1234 commented on May 20, 2024

I'm gonna give a Message metaclass a go for the best performance as you suggested.

from python-betterproto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.