Skip to content

Creating a model performance issue #640

@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

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

    Issue actions