Comments (8)
Gonna give this one a shot 👍
from python-betterproto.
>>> @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.
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.
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.
Actually I take this back it appears to be working now 🤔
from python-betterproto.
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.
The size issues might be due to using it on instances this sure is very strange.
from python-betterproto.
I'm gonna give a Message metaclass a go for the best performance as you suggested.
from python-betterproto.
Related Issues (20)
- TypeError: object AsyncChannel can't be used in 'await' expression
- Strip enum prefixes during compilation HOT 1
- SerializeToString Error for `List of List` HOT 1
- Inconsistency with google protobuf when converting to dict/json with include_default_values=True
- Nested message with repeated field not in to_json when mutated after initialization
- gRPC server example not working HOT 1
- Code Quality: mypy check failed HOT 1
- Complex protos w/ Enums? HOT 2
- Empty fields which one of None HOT 3
- `Struct().from_dict(...)` has no effect HOT 5
- Missing import in generated code when using well known types HOT 1
- Generated code has non-existent relative import HOT 2
- Error parsing proto with map field HOT 3
- Type error on server-side unary-unary handler code
- Invalid code generated when package name contains uppercase letter HOT 1
- Support proto3 optional fields HOT 1
- Warning for optional fields HOT 1
- Make `grpclib` dependency optional HOT 1
- deepcopy with betterproto.Enum fields fails HOT 2
- Enums are set as integers instead of enums when parsing betterproto.Message HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-betterproto.