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

Cythonize trampoline #14

Closed
suned opened this issue Sep 15, 2019 · 0 comments · Fixed by #72
Closed

Cythonize trampoline #14

suned opened this issue Sep 15, 2019 · 0 comments · Fixed by #72
Assignees
Labels
enhancement New feature or request

Comments

@suned
Copy link
Owner

suned commented Sep 15, 2019

Trampoline is used extensively to build stack safe, recursive structures, e.g in reader and state. When interpreting these structures, a significant amount of time is spent in the main loop of Trampoline.run. Consider this:

In [13]: from pfun.reader import value, sequence

In [14]: r = sequence([value(v) for v in range(100000)])

In [15]: %prun r.run(None)
         9799985 function calls in 18.876 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
   100000    7.918    0.000    8.201    0.000 monad.py:31(<lambda>)
        1    5.780    5.780   19.344   19.344 trampoline.py:51(run)
  1599995    1.396    0.000    1.616    0.000 typing.py:806(__new__)
   599996    0.557    0.000    1.350    0.000 trampoline.py:32(and_then)
   200000    0.406    0.000    1.588    0.000 reader.py:45(<lambda>)
   799994    0.402    0.000    0.402    0.000 <string>:1(__init__)
   399996    0.261    0.000   11.689    0.000 trampoline.py:85(_handle_cont)
   600001    0.226    0.000    0.472    0.000 {built-in method builtins.isinstance}
   599996    0.221    0.000   12.953    0.000 trampoline.py:105(_resume)
  1599995    0.220    0.000    0.220    0.000 {built-in method __new__ of type object at 0x107597830}
   199998    0.184    0.000    0.462    0.000 trampoline.py:108(and_then)
   200000    0.180    0.000    0.459    0.000 reader.py:46(<lambda>)
   200000    0.151    0.000    0.588    0.000 reader.py:44(<lambda>)
   200001    0.143    0.000    0.376    0.000 reader.py:95(<lambda>)
   600001    0.139    0.000    0.611    0.000 trampoline.py:28(_is_done)
   199998    0.134    0.000    0.975    0.000 trampoline.py:113(<lambda>)
   600000    0.128    0.000    0.128    0.000 {built-in method _abc._abc_instancecheck}
   600000    0.119    0.000    0.246    0.000 abc.py:137(__instancecheck__)
   100000    0.108    0.000    0.283    0.000 reader.py:84(value)
   100000    0.079    0.000    0.204    0.000 reader.py:26(and_then)
   200000    0.068    0.000    1.043    0.000 trampoline.py:74(_handle_cont)
   100000    0.058    0.000    0.262    0.000 monad.py:30(<lambda>)
        1    0.000    0.000   19.344   19.344 <string>:1(<module>)
        3    0.000    0.000    0.000    0.000 future.py:47(__del__)
        1    0.000    0.000   19.344   19.344 {built-in method builtins.exec}
        1    0.000    0.000   19.344   19.344 reader.py:67(run)
        1    0.000    0.000    0.000    0.000 typing.py:245(inner)
        1    0.000    0.000    0.000    0.000 typing.py:890(cast)
        4    0.000    0.000    0.000    0.000 trampoline.py:89(_resume)
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

Most of the execution time is spent in Trampoline.run. Optimising this loop is therefore a reasonable investment since it will speed up every usage of trampolines.

@suned suned added the enhancement New feature or request label Sep 15, 2019
@suned suned self-assigned this Oct 19, 2019
@suned suned added this to the 0.6.0 milestone Nov 12, 2019
@suned suned removed this from the 0.6.0 milestone Jul 1, 2020
@suned suned mentioned this issue Mar 15, 2021
10 tasks
@suned suned closed this as completed in #72 Apr 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant