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

Optimize ensure_str and ensure_binary. #331

Merged
merged 3 commits into from
May 20, 2020

Conversation

gpshead
Copy link
Contributor

@gpshead gpshead commented May 19, 2020

We found that large applications that have undergone a 2 -> 3 migration
and wound up with a lot of six.ensure_str and six.ensure_binary calls
could save 1-2% CPU usage by optimizing these for the common case.

Further optimization could be done by replacing them with extension
module implementations - assumed out of scope for the pure Python six
project itself.

Ideally all of these calls and use of six in people's code would be
removed after there all need for any Python 2 compatibility is gone.
But completing that kind of type cleanup requires a lot of human
engineering time. This lowers the ongoing costs in the interim.

Contributed by YouTube.

We found that large applications that have undergone a 2 -> 3 migration
and wound up with a lot of six.ensure_str and six.ensure_binary calls
could save 1-2% CPU usage by optimizing these for the common case.

Further optimization could be done by replacing them with extension
module implementations - assumed out of scope for the pure Python six
project itself.

Ideally all of these calls and use of six in people's code would be
removed after there all need for any Python 2 compatibility is gone.
But completing that kind of type cleanup requires a lot of human
engineering time.  This lowers the ongoing costs in the interim.

Contributed by YouTube.
Copy link
Owner

@benjaminp benjaminp left a comment

Choose a reason for hiding this comment

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

Thanks—we have a lot of these calls, too!

Did you check if it helps to do "code motion" on ensure_str to define different functions specialized to PY2 or PY3?

six.py Outdated Show resolved Hide resolved
six.py Outdated Show resolved Hide resolved
@gpshead
Copy link
Contributor Author

gpshead commented May 20, 2020

Did you check if it helps to do "code motion" on ensure_str to define different functions specialized to PY2 or PY3?

Nope, that's a good idea for the future.

@benjaminp benjaminp merged commit 05c4f51 into benjaminp:master May 20, 2020
benjaminp added a commit that referenced this pull request May 20, 2020
@gpshead gpshead deleted the ensure_str_performance branch May 21, 2020 03:19
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.

2 participants