Giter VIP home page Giter VIP logo

Comments (5)

biqqles avatar biqqles commented on July 21, 2024 1

Interesting. I have never got round to benchmarking dataclasses versus this library. I was acutely aware that __call__ is very hot and probably far slower than object.__call__ (which I believe is implemented in C). __new__ is the real equivalent of dataclasses' __init__ so it would be interesting to compare this directly.

I haven't looked at how dataclasses passes arguments to __post_init__, but it's likely it does it statically with metaprogramming rather than dynamically like dataclassy's current __call__ implementation. To be honest, the main reason I haven't obsessed too much about that method is that I use post-init processing very rarely, and when there isn't a custom __init__ dataclassy just uses object.__call__. Now that the library is more or less feature-complete (as I see it so far) performance would be something good to focus on. If it would also be useful to you, any benchmarking you do would likely be very helpful in a new issue.

Anyway, good to know that it's fixed and also that it works with 3.9!

from dataclassy.

biqqles avatar biqqles commented on July 21, 2024

Thanks, I've fixed this but I'm not yet awake enough to be completely sure of exactly why it was broken before or commit a proper test!

from dataclassy.

biqqles avatar biqqles commented on July 21, 2024

Ah, it's because the earlier slice didn't consider the extra *args parameter added in __new__ to allow argument pass-through to __init__.

Not directly related to the bug but now we use a custom __call__ it might be neater to use the keyword-only indicator * instead of *args.

from dataclassy.

biqqles avatar biqqles commented on July 21, 2024

OK, I think that's everything 🙂 If you can confirm everything now works as expected I'll release an update to PyPI.

from dataclassy.

TylerYep avatar TylerYep commented on July 21, 2024

Awesome, I tested it and it works!

As a side note, it seems like dataclassy's performance is roughly twice that of the builtin dataclasses. On the project that encountered this bug (it creates many instances of a single dataclass) I was profiling, the runtime roughly doubles from 4 sec with dataclasses to 8 sec with dataclassy.

Most of the time spent is on dataclassy/dataclassy/dataclass.py:104(__call__) and <string>:1(__new__), tested on Python 3.9.

No rush of course to improve this performance, I just wanted to provide a reference point in case you find it useful.

from dataclassy.

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.