FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-45107: Make LOAD_METHOD_CLASS safer and faster, clean up comments by Fidget-Spinner · Pull Request #28177 · python/cpython · GitHub

/ cpython Public

bpo-45107: Make LOAD_METHOD_CLASS safer and faster, clean up comments - #28177

Merged
Fidget-Spinner merged 6 commits into
python:mainfrom
Fidget-Spinner:micro_opt_lm_class
Sep 17, 2021
Merged

Fidget-Spinner merged 6 commits into
python:mainfrom
Fidget-Spinner:micro_opt_lm_class

Conversation

Fidget-Spinner commented Sep 5, 2021 •
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Member

Fidget-Spinner changed the title [WIP] Optimize LOAD_METHOD specialization, clean up comments bpo-45107: Optimize LOAD_METHOD specialization, clean up comments Sep 5, 2021
Fidget-Spinner removed the request for review from markshannon September 5, 2021 16:40

Fidget-Spinner commented Sep 5, 2021 •
edited
Loading

Copy link
Copy Markdown
Member Author

I'll ping Mark when he's back.

IIUC, LOAD_METHOD_CLASS doesn't need to check cls.__dict__ at all. A single cls.tp_version_tag check is sufficient. So we can save on dict calculation and a branch.

Fidget-Spinner marked this pull request as ready for review September 5, 2021 16:44
Fidget-Spinner added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 5, 2021

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @Fidget-Spinner for commit af0dd27 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 5, 2021
Comment thread Python/ceval.c Outdated

Copy link
Copy Markdown
Member Author

@erlend-aasland the more I look at this the more iffy my code feels.

I'm trying to think if this could cause any segfaults. E.g. it accesses a non-type object at offsetoff(PyTypeObject, tp_version_tag, but the object size is smaller than that location, and it just crashes. I will try to produce some code to test my theory.

Previously the dict check also served as an object identity check since dk_version is unique. With that, accessing tp_version_tag is always safe.

This is guaranteed to always work though if all objects are bigger than offsetoff(PyTypeObject, tp_version_tag). I dont know if thats the case though. Do you remember?

Copy link
Copy Markdown
Contributor

I dont know if thats the case though. Do you remember?

I do not, and unfortunately I do not have any time to investigate now :(

Fidget-Spinner changed the title bpo-45107: Optimize LOAD_METHOD specialization, clean up comments bpo-45107: Make LOAD_METHOD_CLASS safer, clean up comments Sep 15, 2021

Fidget-Spinner commented Sep 15, 2021 •
edited
Loading

Copy link
Copy Markdown
Member Author

Thanks for the review Erlend, ultimately I decided to roll back the changes and make the checks stricter. My tests indicate we lost 0.1% of specialization hits, but the added safety is worth it. I can't prove that accessing tp_version_tag will never segfault in all cases.

markshannon self-assigned this Sep 15, 2021

markshannon left a comment

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It looks like we missed a check that the operand of LOAD_METHOD_CLASS is actually a class.

Comment thread Python/ceval.c Outdated
Comment thread Python/ceval.c Outdated
Fidget-Spinner changed the title bpo-45107: Make LOAD_METHOD_CLASS safer, clean up comments bpo-45107: Make LOAD_METHOD_CLASS safer and faster, clean up comments Sep 16, 2021

Copy link
Copy Markdown
Member

Looks good, thanks.
Don't know what is up with the Windows builds 😕

Copy link
Copy Markdown
Member Author

FWIW, I can't repro the windows build errors locally. It seems to be affecting every PR right now.

Fidget-Spinner merged commit 70bed6f into python:main Sep 17, 2021
Fidget-Spinner deleted the micro_opt_lm_class branch September 17, 2021 10:47

Copy link
Copy Markdown
Member Author

Thanks Mark and Erlend for the reviews!

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL