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

Fixed #25750 -- Made Options._expire_cache faster #5649

Closed
wants to merge 1 commit into from
Closed

Fixed #25750 -- Made Options._expire_cache faster #5649

wants to merge 1 commit into from

Conversation

patrys
Copy link
Contributor

@patrys patrys commented Nov 13, 2015

Made Options._expire_cache much faster by avoiding unnecessary list operations and by avoiding delattr calls that would result in an exception being raised as it involves call frame reconstruction which is very costly. Especially so in a function that is called millions of times.

Relevant ticket: https://code.djangoproject.com/ticket/25750

@patrys
Copy link
Contributor Author

patrys commented Nov 13, 2015

There are so many typos in that commit message that I'll amend it to not embarass myself any further.

Made Options._expire_cache much faster by avoiding unnecessary list
operations and by avoiding `delattr` calls that would result in an
exception being raised as it involves call frame reconstruction
which is very costly. Especially so in a function that is called
millions of times.
REVERSE_PROPERTIES = ('related_objects', 'fields_map', '_relation_tree')
FORWARD_PROPERTIES = {'fields', 'many_to_many', 'concrete_fields',
'local_concrete_fields', '_forward_fields_map'}
REVERSE_PROPERTIES = {'related_objects', 'fields_map', '_relation_tree'}
Copy link
Member

Choose a reason for hiding this comment

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

For what I've read about performance, sets perform better when testing membership and lists perform better when iterating over (which seems the case here). To be checked...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not a matter of performance. We care about a particular set of values, not about their particular order. Set is the idiomatic Python type to use here.

Copy link
Member

Choose a reason for hiding this comment

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

Fair, but we are still in a critical section of code performance-wise.

Copy link
Contributor

Choose a reason for hiding this comment

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

While my tests suggest that iterating a set is ~8% slower in this case, it is a negligible difference once you look at the whole _expire_cache function.

Copy link
Member

Choose a reason for hiding this comment

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

OK, let's ignore my comment, then. Thanks for testing.

@timgraham
Copy link
Member

merged in 7628f87, thanks!

@timgraham timgraham closed this Nov 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants