• Kirill Smelkov's avatar
    pyx api: Provide go · f971a2a8
    Kirill Smelkov authored
    - Add go functionality to libgolang runtime;
    - Implement go for thread and gevent runtimes.
    
      * Thread runtime uses PyThread_start_new_thread which, if used
        carefully, does not depend on Python GIL and on e.g. POSIX reduces to
        tiny wrapper around pthread_create.
    
      * Gevent runtime uses gevent's Greenlet in Pyx mode. This turns
        gevent to be a build-time dependency.
    
    - Provide low-level _taskgo in C client API;
    - Provide type-safe C++-level go wrapper over _taskgo;
    - Switch golang.go from py implementation into Pyx wrapper over
      Pyx/nogil API.
    
    This is the first patch that adds Pyx/C++/C-level unit tests and hooks
    them into golang_test.py .
    
    This patch brings the following speedup to Python-level interface:
    
     (on i7@2.6GHz)
    
    thread runtime:
    
        name             old time/op  new time/op  delta
        go               93.0µs ± 1%  26.6µs ± 1%  -71.41%  (p=0.000 n=10+10)
        chan             13.6µs ± 2%  13.7µs ± 1%     ~     (p=0.280 n=10+10)
        select           29.9µs ± 4%  29.3µs ± 2%   -1.89%  (p=0.017 n=10+9)
        def              61.0ns ± 0%  55.0ns ± 0%   -9.84%  (p=0.000 n=10+10)
        func_def         43.8µs ± 1%  44.0µs ± 1%   +0.66%  (p=0.006 n=10+10)
        call             62.5ns ± 1%  64.0ns ± 0%   +2.40%  (p=0.000 n=10+8)
        func_call        1.06µs ± 1%  1.09µs ± 1%   +2.72%  (p=0.000 n=10+10)
        try_finally       137ns ± 0%   139ns ± 2%   +1.17%  (p=0.033 n=10+10)
        defer            2.34µs ± 1%  2.36µs ± 1%   +0.84%  (p=0.015 n=10+10)
        workgroup_empty  96.1µs ± 1%  58.1µs ± 1%  -39.55%  (p=0.000 n=10+10)
        workgroup_raise   135µs ± 1%    73µs ± 1%  -45.97%  (p=0.000 n=10+10)
    
    gevent runtime:
    
        name             old time/op  new time/op  delta
        go               68.8µs ± 1%  28.6µs ± 0%  -58.47%  (p=0.000 n=10+8)
        chan             14.8µs ± 1%  15.8µs ± 1%   +6.19%  (p=0.000 n=10+10)
        select           32.0µs ± 0%  33.1µs ± 1%   +3.25%  (p=0.000 n=10+10)
        def              58.0ns ± 0%  55.0ns ± 0%   -5.17%  (p=0.000 n=10+10)
        func_def         43.9µs ± 1%  44.4µs ± 2%   +1.20%  (p=0.007 n=10+10)
        call             63.5ns ± 1%  64.0ns ± 2%     ~     (p=0.307 n=10+10)
        func_call        1.08µs ± 1%  1.06µs ± 0%   -2.55%  (p=0.000 n=10+8)
        try_finally       142ns ± 0%   136ns ± 0%   -4.23%  (p=0.000 n=10+9)
        defer            2.32µs ± 1%  2.29µs ± 1%   -0.96%  (p=0.000 n=10+10)
        workgroup_empty  90.3µs ± 0%  73.8µs ± 1%  -18.29%  (p=0.000 n=10+10)
        workgroup_raise   108µs ± 1%    94µs ± 0%  -13.29%  (p=0.000 n=10+10)
    
    (small changes are probably within noise; "go" and "workgroup_*" should be
    representative)
    f971a2a8
libgolang.h 4.85 KB