-
Notifications
You must be signed in to change notification settings - Fork 124
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
Cythonize the call loop #263
Open
goodboy
wants to merge
11
commits into
pytest-dev:main
Choose a base branch
from
goodboy:cythonize_call_loop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
995c1ba
Turn callers module into package
e586fb5
Cythonize the call loop
a0ffaa6
Build cython extension in packaging
7bd1ec5
Include cython in tox benchmark tests
08db646
Install cython in travis env
e003fc4
Fix install to include cython
goodboy 323ce41
Move import to bottom of mod; rename c func.
goodboy 044aa54
Revert "Drop `callertype` fixture from benchmark tests"
goodboy c17cfeb
Include cythonized multicall in benchmarks
goodboy b826f75
Port callers to new _result.py module
goodboy f5d4eb4
Appease black linter
goodboy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ requires = [ | |
"setuptools", | ||
"setuptools-scm", | ||
"wheel", | ||
"Cython", | ||
] | ||
|
||
[tool.towncrier] | ||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
""" | ||
Cynthonized hook call loop. | ||
|
||
This is currently maintained as a verbatim copy of | ||
``pluggy.callers._multicall()``. | ||
|
||
NOTE: In order to build this source you must have cython installed. | ||
""" | ||
import sys | ||
|
||
from .._result import _Result, _raise_wrapfail, HookCallError | ||
|
||
|
||
cpdef _c_multicall(list hook_impls, dict caller_kwargs, bint firstresult=False): | ||
"""Execute a call into multiple python functions/methods and return the | ||
result(s). | ||
|
||
``caller_kwargs`` comes from _HookCaller.__call__(). | ||
""" | ||
__tracebackhide__ = True | ||
results = [] | ||
excinfo = None | ||
try: # run impl and wrapper setup functions in a loop | ||
teardowns = [] | ||
try: | ||
for hook_impl in reversed(hook_impls): | ||
try: | ||
args = [caller_kwargs[argname] for argname in hook_impl.argnames] | ||
except KeyError: | ||
for argname in hook_impl.argnames: | ||
if argname not in caller_kwargs: | ||
raise HookCallError( | ||
"hook call must provide argument %r" % (argname,)) | ||
|
||
if hook_impl.hookwrapper: | ||
try: | ||
gen = hook_impl.function(*args) | ||
next(gen) # first yield | ||
teardowns.append(gen) | ||
except StopIteration: | ||
_raise_wrapfail(gen, "did not yield") | ||
else: | ||
res = hook_impl.function(*args) | ||
if res is not None: | ||
results.append(res) | ||
if firstresult: # halt further impl calls | ||
break | ||
except BaseException: | ||
excinfo = sys.exc_info() | ||
finally: | ||
if firstresult: # first result hooks return a single value | ||
outcome = _Result(results[0] if results else None, excinfo) | ||
else: | ||
outcome = _Result(results, excinfo) | ||
|
||
# run all wrapper post-yield blocks | ||
for gen in reversed(teardowns): | ||
try: | ||
gen.send(outcome) | ||
_raise_wrapfail(gen, "has second yield") | ||
except StopIteration: | ||
pass | ||
|
||
return outcome.get_result() |
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i wonder if there is a way to line up implementations better so we cna do less work and less work on calls,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RonnyPfannschmidt oh there definitely is. I actually have some ideas but it's going to require some rejigging of how implementations are stored/managed in the manger iirc and I think this may have something to do with the way we couple tracing to that management (see #262 and #217). I also think we should let @bluetech play with it in the context of
pytest
before we get too ahead of ourselves - micro-benchmarks shouldn't be our guiding light IMO.I also thought about this a while back with ideas for the rework of internals.. let's see if I can find some notes.
@RonnyPfannschmidt another question I have is how to implement both of these implementations (cython and python) without too much duplicate work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@goodboy as cython has a python mode, where a annotated file is next to the implementation file, i beleive we can do it better these days (by implementing it in python, and then cythonizing those files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So then it is as simple as running cython on the original code?
Haven't looked at cython in ages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im going to sprint on this next week, i hope to get a sync with simon from datasette about async use of pluggy before so we can enable that as well