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

Performance optimizations #1725

Merged
merged 4 commits into from Nov 4, 2022

Conversation

antonpirker
Copy link
Member

@antonpirker antonpirker commented Nov 4, 2022

Our Django signals integrations added a lot of overhead in some cases.
See: #1721

This code runs now over an order of magnitude faster for getting the name of a partials.

Closes #1721

elif hasattr(
receiver, "func"
): # certain functions (like partials) dont have a name
name = "partial(<function " + receiver.func.__name__ + ">)" # type: ignore
Copy link
Member

Choose a reason for hiding this comment

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

can the func itself be a partial?

Copy link
Member Author

Choose a reason for hiding this comment

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

F*ck... Probably... I will check on Monday

Copy link
Member Author

Choose a reason for hiding this comment

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

I will check now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, func appears to always be the function:

Python 3.10.8 (main, Oct 13 2022, 09:48:40) [Clang 14.0.0 (clang-1400.0.29.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def f(a, b, c, x):
...     return 1000*a + 100*b + 10*c + x
... 
>>> f
<function f at 0x102752050>
>>> from functools import partial
>>> g = partial(f, 3)
>>> h = partial(g, 1)
>>> g
functools.partial(<function f at 0x102752050>, 3)
>>> h
functools.partial(<function f at 0x102752050>, 3, 1)
>>> h(3, 4)
3134
>>> h.func
<function f at 0x102752050>
>>> g.func
<function f at 0x102752050>

Copy link
Member

Choose a reason for hiding this comment

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

cool, thx for checking

Copy link
Member

@sl0thentr0py sl0thentr0py left a comment

Choose a reason for hiding this comment

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

change is fine, but why was it slow in the first place?

@antonpirker
Copy link
Member Author

Because str(bla) is very very slow compared to bla.__name__.

I will see if the user can test this and confirm that it makes the situation way better before I merge.

@antonpirker antonpirker merged commit 76b413a into master Nov 4, 2022
@antonpirker antonpirker deleted the antonpirker/1721-django-performance-regression branch November 4, 2022 16:58
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.

Performance regression with Django
2 participants