-
Notifications
You must be signed in to change notification settings - Fork 51
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Maybe rewrite small functions like map
in Python.
#91
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
Comments
The idea is definitely worth exploring, though maybe not with |
Though the docs for map() don't mention its type-ness -- it's listed under Builtin Functions and the text just says it returns an iterator. I'm sure it will break someone's code. But maybe specialization can help avoid that. |
Using the code from https://docs.python.org/3/library/functions.html
(Not sure why the
|
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Consider
map(func, seq)
, wherefunc
is a Python function.This calls from Python into a builtin function, and then calls back into Python.
Once we have fast Python to Python calls, it might be beneficial to convert
map
and similar functions into Python.E.g. consider the common case of a single iterable.
map(f, i)
is equivalent to(f(x) for x in i)
The above would allow us to avoid C calls, with the possibility of a speedup within the interpreter and the possibility of a larger speedup with a hypothetical JIT.
For maximum efficiency we might want to write
map
in Python.compiles to:
Which has an loop of 8 instructions (7 allowing for superinstructions).
The question is:
Does the additional interpreter overhead of the dispatch cost more or less than the call to a C function and the call back into the interpreter?
My guess is that it with specialized
CALL_FUNCTION
andFOR_ITER
, the Python version will be about a little faster than the C version iffunc
is a Python function, and a bit slower iffunc
is a builtin function.But that is just guess.
The text was updated successfully, but these errors were encountered: