GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-40170: Add _PyObject_CheckBuffer() internal function by shihai1991 · Pull Request #19541 · python/cpython

Conversation

@shihai1991

@shihai1991 shihai1991 commented Apr 15, 2020 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

https://bugs.python.org/issue40170

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@shihai1991
Add _PyObject_CheckBuffer() internal function
11f0155
@shihai1991
shihai1991 requested review from a team and tiran as code owners April 15, 2020 15:35
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Apr 15, 2020
@bedevere-bot bedevere-bot added the awaiting review label Apr 15, 2020
@shihai1991
update head file of winreg
e5372f8
@shihai1991

shihai1991 commented Apr 15, 2020

Copy link
Copy Markdown
Member Author

@vstinner Hi, victor. Looks like _PyObject_CheckBuffer() should be added, right?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Apr 15, 2020

Copy link
Copy Markdown
Member

@vstinner Hi, victor. Looks like _PyObject_CheckBuffer() should be added, right?

I chose to not add an internal _PyObject_CheckBuffer() on purpose, to simplify the implementation. I don't think that it's worth it.

@methane, @pablogsal: What do you think?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner added the skip news label Apr 15, 2020
@vstinner

vstinner commented Apr 15, 2020

Copy link
Copy Markdown
Member

This change is related to my commit ef5c615 which converted the PyObject_CheckBuffer() macro to a function.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@methane

methane commented Apr 16, 2020

Copy link
Copy Markdown
Member

I feel this API is not performance-critical. So I agree with @vstinner.

Would you provide a benchmark if you think this API is important?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@shihai1991

shihai1991 commented Apr 16, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

I feel this API is not performance-critical. So I agree with @vstinner.

Would you provide a benchmark if you think this API is important?

Oh, I was unware victor's intension before :(

I run $ ./python -m pyperf timeit --compare-to python3.9d "bytearray(range(10))" three times:

Mean +- std dev: [python3.9d] 1.84 us +- 0.29 us -> [python] 1.76 us +- 0.23 us: 1.04x faster (-4%)
Not significant!

Mean +- std dev: [python3.9d] 1.87 us +- 0.32 us -> [python] 1.82 us +- 0.18 us: 1.02x faster (-2%)
Not significant!

Mean +- std dev: [python3.9d] 1.96 us +- 0.35 us -> [python] 1.84 us +- 0.22 us: 1.06x faster (-6%)

little improvment ;(

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Apr 16, 2020

Copy link
Copy Markdown
Member

I run (...) three times: (...)

Remark about your benchmark: the std dev is quite big in you take in account the small difference (50 nanoseconds). For benchmarks which are close to nanoseconds, it's better to use CPU isolation if possible: https://pyperf.readthedocs.io/en/latest/system.html

Rather than running the benchmark 3 times, you can ask pyperf to compute more values. For example, use -p 100 to spawn 100 processes (sequentially) rather than 20. See the doc:
https://pyperf.readthedocs.io/en/latest/run_benchmark.html#runs-values-warmups-outer-and-inner-loops

Moreover, what is the D in "python3.9d"? Is it a debug build? Benchmarks are more reliable when run on a binary compiled in release mode with LTO + PGO.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Apr 16, 2020

Copy link
Copy Markdown
Member

little improvment ;(

Honestly, I don't think that it's worth it to bother with this micro-optimization. Calling PyObject_CheckBuffer() is likely to take less than 50 nanoseconds. I close the issue.

It's all about tradeoffs. It depends if a function is commonly used or not. Here I don't think that it's worth it o bother with inlining.

Moreover, using LTO, the compiler may be allowed to inline PyObject_CheckBuffer() anyway, especially when using -fno-semantic-interposition which is used by default in Clang. FYI We modified the Python package in Fedora to use -fno-semantic-interposition so GCC can inline function calls from libpython to libpython (Pyhon is built with --enable-shared on Fedora to get libpython).

shihai1991 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner closed this Apr 16, 2020
@shihai1991

shihai1991 commented Apr 16, 2020

Copy link
Copy Markdown
Member Author

little improvment ;(

Honestly, I don't think that it's worth it to bother with this micro-optimization. Calling PyObject_CheckBuffer() is likely to take less than 50 nanoseconds. I close the issue.

It's all about tradeoffs. It depends if a function is commonly used or not. Here I don't think that it's worth it o bother with inlining.

Moreover, using LTO, the compiler may be allowed to inline PyObject_CheckBuffer() anyway, especially when using -fno-semantic-interposition which is used by default in Clang. FYI We modified the Python package in Fedora to use -fno-semantic-interposition so GCC can inline function calls from libpython to libpython (Pyhon is built with --enable-shared on Fedora to get libpython).

Wow, thanks a million, victor. Learned much from your info.

Moreover, what is the D in "python3.9d"? Is it a debug build?
Yes, I use ./configure --with-pydebug --with-trace-refs && make install to install the master vision.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@shihai1991
shihai1991 deleted the bpo_40170_1 branch April 16, 2020 15:17
@vstinner

vstinner commented Apr 16, 2020

Copy link
Copy Markdown
Member

Yes, I use ./configure --with-pydebug --with-trace-refs && make install to install the master vision.

Please don't run benchmarks on a debug build: they contain many debug checks which are run at runtime.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@shihai1991

shihai1991 commented Apr 16, 2020

Copy link
Copy Markdown
Member Author

Yes, I use ./configure --with-pydebug --with-trace-refs && make install to install the master vision.

Please don't run benchmarks on a debug build: they contain many debug checks which are run at runtime.

Copy that. Thanks for your guide.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@tiran tiran Awaiting requested review from tiran

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@shihai1991 @vstinner @methane @the-knights-who-say-ni @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.