Skip to content

Creating a model performance issue #640

Open
@needones

Description

@needones

I used viztracer to analyze the performance of HashModel and BaseModel, and found that the time difference between the two was hundreds of times when the model was generated, and a large number of Deepcopies were generated when the HashModel was generated, but I could not locate the problem, Is the pydantic v1 version causing the problem?

create model cost:
BaseModel ~= 3us
HashModel ~= 700us

python:3.11
viztracer==0.16.3
redis-om==0.3.1
redis == 5.0.6

eg: demo.py

from pydantic import BaseModel
from redis_om import HashModel


class TaskStatisticalModel(BaseModel):
    task_uuid: str = ""
    parallel_task: str = ""
    is_alarm: int = 0


class TaskStatisticalModel2(HashModel):
    task_uuid: str = ""
    parallel_task: str = ""
    is_alarm: int = 0


def add_redis_model():
    TaskStatisticalModel2()


def add_base_model():
    TaskStatisticalModel()


def test_redis_model(number=10):
    for i in range(number):
        add_redis_model()


def test_base_model(number=10):
    for i in range(number):
        add_base_model()


if __name__ == '__main__':
    num = 10
    test_redis_model(num)
    test_base_model(num)

use viztracer

viztracer demo.py

# wait
vizviewer result.json

search:
"add_redis_model" => hash_model
"add_base_model" => base model

image

image

Activity

XChikuX

XChikuX commented on Jan 10, 2025

@XChikuX

HashModel, JsonModel, EmbeddedJsonModel have several custom logic to ensure the data is modified for compatability purposes.

Using BaseModel for redis-om will lead to unexpected behaviour and is not supported.

Some latency is expected. However, this many deep copies is concerning @slorello89

We have a good pictoral walkthrough from OP. Can we reduce the number of deepcopies?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @XChikuX@needones

        Issue actions

          Creating a model performance issue · Issue #640 · redis/redis-om-python