试用Meta开发的python运行时CinderX

张开发
2026/5/24 13:25:13 15 分钟阅读
试用Meta开发的python运行时CinderX
存储库地址https://www.github.com/facebookincubator/cinderxCinderX 是一个提升 Python 性能的 Python 扩展 运行时。现状CinderX 正在积极开发中。它在Meta的生产中被用于 比如Instagram的Django服务。它是实验性的 外部用户。新版本每周发布到 PyPI。特色JIT 编译器 - 将 Python 字节码实时编译为原生 机器码静态 Python - Python 的一种更严格的形式/子集用于类型安全和 优化代码库还包括其他功能比如并行垃圾收集器 以及一个更轻量级的Python解释器帧实现。 不过这些功能目前还不兼容CPython的原厂运行时。要求Python 3.14.3 或更高版本Linuxx86_64GCC 13 或 Clang 18扩展应该能在macOS上构建和导入但大多数功能都会 运行时禁用。Windows目前还完全不支持。切到wsl环境安装利用uv的虚拟环境功能安装python 3.14.3C:\Users\ltwsl rootDESKTOP-59T6U68:/mnt/c/Users/lt# docker start gcc gcc rootDESKTOP-59T6U68:/mnt/c/Users/lt# docker exec -it gcc bash root6ae32a5ffcde:/# cd /par root6ae32a5ffcde:/par# uv python list cpython-3.15.0a7-linux-x86_64-gnu download available cpython-3.15.0a7freethreaded-linux-x86_64-gnu download available cpython-3.14.3-linux-x86_64-gnu download available cpython-3.14.3freethreaded-linux-x86_64-gnu download available cpython-3.13.12-linux-x86_64-gnu download available cpython-3.13.12freethreaded-linux-x86_64-gnu download available cpython-3.12.13-linux-x86_64-gnu download available cpython-3.11.15-linux-x86_64-gnu download available cpython-3.11.2-linux-x86_64-gnu /usr/bin/python3.11 cpython-3.11.2-linux-x86_64-gnu /usr/bin/python3 - python3.11 root6ae32a5ffcde:/par# mkdir uv314 root6ae32a5ffcde:/par# cd uv314 root6ae32a5ffcde:/par/uv314# uv python install cpython-3.14.3 Installed Python 3.14.3 in 52.85s cpython-3.14.3-linux-x86_64-gnu (python3.14) warning: /root/.local/bin is not on your PATH. To use installed Python executables, run export PATH/root/.local/bin:$PATH or uv python update-shell. root6ae32a5ffcde:/par/uv314# uv python update-shell Updated configuration file: /root/.profile Updated configuration file: /root/.bashrc Restart your shell to apply changes root6ae32a5ffcde:/par/uv314# exit rootDESKTOP-59T6U68:/mnt/c/Users/lt# docker exec -it gcc bash root6ae32a5ffcde:/# cd /par/uv314 root6ae32a5ffcde:/par/uv314# uv venv --python 3.14 Using CPython 3.14.3 Creating virtual environment at: .venv Activate with: source .venv/bin/activate root6ae32a5ffcde:/par/uv314# source .venv/bin/activate (uv314) root6ae32a5ffcde:/par/uv314# python3.14 /par/pip.pyz install cinderx Looking in indexes: https://mirrors.aliyun.com/pypi/simple Collecting cinderx Downloading https://mirrors.aliyun.com/pypi/packages/49/7d/bc2b942d956743049be159731eebd061185957fc7c0c50baca5864816142/cinderx-2026.3.30.0-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (29.4 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 29.4/29.4 MB 772.7 kB/s eta 0:00:00 Installing collected packages: cinderx Successfully installed cinderx-2026.3.30.0测试先在交互式界面导入插件设置编译前调用次数阈值再定义函数(uv314) root6ae32a5ffcde:/par/uv314# python Python 3.14.3 (main, Mar 20 2026, 00:34:32) [Clang 22.1.1 ] on linux Type help, copyright, credits or license for more information. import cinderx.jit cinderx.jit.compile_after_n_calls(1) import time def solve_T16(): ... ... seen.add(N) ... total_sum N ... print(fN{N}, a{a}, b{b}, k{k}, s{s}) ... s d ... ... # 同样处理 s ≡ 1 (mod f), s ≡ 0 (mod g) 的情况 ... # 交换 f 和 g 的角色 ... inv_g_mod_f pow(g, -1, f) ... s1 g * inv_g_mod_f % (f * g) ... s1 s1 % d ... if s1 0: ... s1 d ... s s1 ... while s max_s: ... if s 2: ... numerator s * (pow10_k - s) ... if numerator % d 0: ... b numerator // d ... if min_b b max_b: ... a s - b ... if a 0: ... N a * pow10_k b ... if len(str(N)) n and N not in seen: ... seen.add(N) ... total_sum N ... #print(fN{N}, a{a}, b{b}, k{k}, s{s}) ... s d ... ... return total_sum ... ttime.time();result solve_T16();ttime.time()-t;print(fT(16) {result}.time{t}) N2499500025000000, a24995000, b25000000, k8, s49995000 T(16) 72673459417881349.time9.91115427017212 ttime.time();result solve_T16();ttime.time()-t;print(fT(16) {result}.time{t}) N2499500025000000, a24995000, b25000000, k8, s49995000 T(16) 72673459417881349.time4.377968072891235 ttime.time();result solve_T16();ttime.time()-t;print(fT(16) {result}.time{t}) N2499500025000000, a24995000, b25000000, k8, s49995000 T(16) 72673459417881349.time4.429172039031982 可见第一次执行solve_T16()用时9.9秒后2次都是4.4秒左右。而原始程序在python中执行时间如下。(uv314) root6ae32a5ffcde:/par/uv314# time python pe932e.py N2499500025000000, a24995000, b25000000, k8, s49995000 T(16) 72673459417881349.time6.847144365310669 real 0m6.911s user 0m6.880s sys 0m0.000s可见第一次运行慢于python后2次JIT后快了50%。将上述import cinderx.jit和cinderx.jit.compile_after_n_calls(1)写入脚本。(uv314) root6ae32a5ffcde:/par/uv314# time python pe932e.py N2499500025000000, a24995000, b25000000, k8, s49995000 T(16) 72673459417881349.time9.779442310333252 N2499500025000000, a24995000, b25000000, k8, s49995000 T(16) 72673459417881349.time4.061721086502075 real 0m14.055s user 0m13.764s sys 0m0.010s (uv314) root6ae32a5ffcde:/par/uv314#执行的效果和交互界面一样。

更多文章