Skip to content

Ref #36912 - Added benchmarks for Q and Q.create()#98

Open
amakarudze wants to merge 5 commits intodjango:mainfrom
amakarudze:q-create
Open

Ref #36912 - Added benchmarks for Q and Q.create()#98
amakarudze wants to merge 5 commits intodjango:mainfrom
amakarudze:q-create

Conversation

@amakarudze
Copy link
Copy Markdown

@amakarudze amakarudze commented Mar 29, 2026

Added benchmarks for Q.create() in benchmarks/query_benchmarks/query_utils_q_create and Q in benchmarks/query_benchmarks/query_utils_q to be used in Ticket 36912 for comparison on whether to add validation to Q.create().

@amakarudze amakarudze marked this pull request as draft March 29, 2026 16:38
Content.objects.all().delete()

def time_q_create(self):
content_list = list(Content.objects.all())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! A quick note here. I'm not so familiar with how django-asv works, but it looks like this database call is in the snippet being benchmarked. I think your benchmark needs to ensure it only calls Q() or Q.create().

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Jacob, I was unsure whether database calls were necessary or not. I am still trying to find my way around django-asv.

@amakarudze amakarudze changed the title Add benchmark for Q.create() Ref #36912 - Add benchmarks for Q and Q.create() Apr 11, 2026
@amakarudze amakarudze marked this pull request as ready for review April 11, 2026 18:16
@amakarudze amakarudze changed the title Ref #36912 - Add benchmarks for Q and Q.create() Ref #36912 - Added benchmarks for Q and Q.create() Apr 11, 2026
Copy link
Copy Markdown
Collaborator

@sarahboyce sarahboyce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @amakarudze! ⭐
I have a few minor suggestions, after addressing these would you mind squashing to a single commit? ❤️

]

def time_create_no_args(self):
return Q().create(children=self.children_no_args)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return Q().create(children=self.children_no_args)
for _ in range(100):
Q().create(children=self.children_no_args)

Suggestions:

  • in some benchmarks we run them multiple times to exaggerate changes, we might want to do this with all of the benchmarks
  • I think a return is not necessary and doesn't match the format of other benchmarks

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the loop makes a lot of sense given the main concern is that Q.create is sometimes called in loops

from ...utils import bench_setup


class TimeQInit:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These appear to be missing the Q calls?

Comment thread results/benchmarks.json
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at other recently added benchmarks (e.g. #95), we do not need to update the results/benchmarks.json file. I have a feeling we should ideally git ignore this file

Copy link
Copy Markdown
Collaborator

@sarahboyce sarahboyce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amakarudze I have added more comments

I feel what we are missing are the results of these benchmarks against main and against the new branch with the validation

@@ -0,0 +1,33 @@
from ...utils import bench_setup
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually don't need this benchmark for the ticket I imagine. I think we are only evaluating the cost of having the validation added to Q.create

]

def time_create_no_args(self):
return Q().create(children=self.children_no_args)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the loop makes a lot of sense given the main concern is that Q.create is sometimes called in loops

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

Successfully merging this pull request may close these issues.

3 participants