Skip to content

Optimize property to cached_property #36

Open
@WH-2099

Description

@WH-2099

Hello, first of all, thank you for your open source contribution. We have been using this package in production for a while and it works great.

In our usage scenario, we will pass the instantiated object of ULID as the key field of pydantic.BaseModel as the key context for data processing.
In different processing processes (actually, relatively independent functions of multiple interfaces), since ULID itself carries a timestamp, we will use it as the source of the data timestamp.
Therefore, there will be scenarios where the same ULID object is accessed multiple times using properties such as datetime.
When dealing with relatively large amounts of data (in the billions), this can cause the property to be evaluated repeatedly, which can have a certain impact on performance.

Therefore I would like to propose replacing the property decorator with a cached_property with caching, which can optimize the performance of multiple accesses to the property.
Of course, for a single attribute access, this might incur a slight memory penalty, but I think this is acceptable (after all, the int size in CPython 3.13 is a whopping 28 bytes).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions