Giter Site home page Giter Site logo

Comments (11)

pxeger avatar pxeger commented on May 13, 2024 1

I don't know how much of a difference it will make, but the codebase is pretty class-heavy so I'm optimistic

from authentik.

BeryJu avatar BeryJu commented on May 13, 2024

Hey, I wasn't aware that __slots__ makes this much of a difference, I am looking forward to seeing what the PR will bring!

from authentik.

traverseda avatar traverseda commented on May 13, 2024

PyPy does some optimisations like this already.

PyPy uses JIT, which generally uses a lot more memory, has slower startup times, but works faster. I'd expect most code running in PyPy to use more memory, unless you're getting to the hundred's of MB range. I'd be pretty surprised is slots helped that much either, definitely I don't think you should apply it to all classes but if there's some class that's getting instantiated thousands of times it would be a good thing to look at optimizing.

Is this project really instantiating thousands and thousands of classes?

from authentik.

BeryJu avatar BeryJu commented on May 13, 2024

There are some classes that are instantiated a lot (especially for the PolicyEngine), but a lot of the other classes use a lot of inheritance.

Most things in this projects are class based, simply just because of django and drf.

from authentik.

traverseda avatar traverseda commented on May 13, 2024

Well it will be interesting to see if this has any significant impact

from authentik.

pxeger avatar pxeger commented on May 13, 2024

The PyPy comment was based on this page about __slots__ which says PyPy "does these optimisations by default", which I just blindly trusted. Maybe that's totally wrong, I don't know

from authentik.

james-d-elliott avatar james-d-elliott commented on May 13, 2024

How __slots__ works is by telling the python interpreter to only expect objects to only contain certain attributes which makes the objects not use dicts to store them in memory. The reason why this has an effect on memory consumption is how the data is structured in memory. It also has an additional benefit of improving the time it takes to get/set the attributes. PyPy does indeed do this by default, it using more memory on average is not indicative of how it will change a project that doesn't use it as PyPy drastically alters the way python operates in other ways (JIT instead of interpreted).

The only downside is you cannot get/set attributes that do not exist in this array and ALL objects in the inheritance chain MAY NOT use dicts for memory storage, i.e. they MUST also define __slots__. One other piece of information is that __slots__ is inherited also. Technically it's better to allow __slots__ to be inherited, i.e. don't define an attribute twice; however you can do so if you must/desire, it will just use a bit more memory.

from authentik.

stale avatar stale commented on May 13, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from authentik.

traverseda avatar traverseda commented on May 13, 2024

I hate stale closing bot. It's the worst bot. I mean don't get my wrong, I don't think adding __slots__ to all classes makes sense, but stale-close bot it still the worst.

from authentik.

pxeger avatar pxeger commented on May 13, 2024

I got bored of working on this, so it's fine for stale bot to close it if it wants.

from authentik.

BeryJu avatar BeryJu commented on May 13, 2024

@traverseda My bad, I didn't fully think through configuring stale bot when I initially added it.

I re-opened this issue with a pr_wanted label, which won't be closed by stale bot, and essentially means its a nice feature/addition, that I don't (currently) plan on adding myself, but I am open to PRs for it.

from authentik.

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.