Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a model performance issue #640

Open
needones opened this issue Jul 26, 2024 · 0 comments
Open

Creating a model performance issue #640

needones opened this issue Jul 26, 2024 · 0 comments

Comments

@needones
Copy link

needones commented Jul 26, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant