pythonfaster 1.8.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,362 @@
1
+ Metadata-Version: 2.4
2
+ Name: pythonfaster
3
+ Version: 1.8.0
4
+ Summary: Transparent Python acceleration — compile .py to native code on import, zero source changes
5
+ Author: pythonfaster contributors
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/15525730080/pythonfaster
8
+ Project-URL: Documentation, https://github.com/15525730080/pythonfaster#readme
9
+ Project-URL: Repository, https://github.com/15525730080/pythonfaster
10
+ Project-URL: Issues, https://github.com/15525730080/pythonfaster/issues
11
+ Keywords: python,acceleration,cython,aot,compilation,performance,speedup,native,import-hook
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Cython
21
+ Classifier: Topic :: Software Development :: Compilers
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: Cython>=3.0
27
+ Requires-Dist: setuptools>=68.0
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=7.0; extra == "dev"
30
+ Requires-Dist: build; extra == "dev"
31
+ Requires-Dist: twine>=4.0; extra == "dev"
32
+ Dynamic: license-file
33
+
34
+ # pythonfaster
35
+
36
+ > Transparent Python acceleration. Import your project once — it runs compiled.
37
+
38
+ `pythonfaster` hooks Python's import machinery and compiles your `.py` modules to native machine code via Cython, automatically. No decorators, no type annotations, no source changes. Type inference, class-layout conversion, and method-call lowering happen behind the import hook. If any step is unsafe or fails, it silently falls back to normal Python — your program never breaks.
39
+
40
+ [中文文档](README_zh-CN.md)
41
+
42
+ ## What is this project?
43
+
44
+ `pythonfaster` is a project that makes Python fast. The goal in one sentence: without changing a single line of code, lift Python's runtime performance to the same tier as Node.js and Java. Python traditionally sits in the bottom tier of language performance — pythonfaster closes that gap through compilation.
45
+
46
+ ## How much faster?
47
+
48
+ Measured on all 10 [Computer Language Benchmarks Game](https://salsa.debian.org/benchmarksgame-team/benchmarksgame/) (CLBG) programs at official reference workload sizes, then calibrated to the official CLBG language ranking (C = 1.00×; the multiplier means "how many times slower than C"):
49
+
50
+ ![Cross-language ranking](benchmarks/results/current/language_comparison.png)
51
+
52
+ **CPython 3.12 runs the CLBG suite 55.1× slower than C. The same code under pythonfaster runs 7.04× slower than C — a 7.82× geometric-mean speedup that moves Python from the bottom tier into the same tier as Node.js (6.63×), within 2× of Java (3.69×), and 2.5× faster than PyPy.**
53
+
54
+ In the official 31-language CLBG ranking, that is a jump from 29th place to 19th — right between Node.js (18th) and Racket (20th). Key languages are excerpted below (full 31-language table in the appendix at the end):
55
+
56
+ | Rank | Language | vs C |
57
+ |---:|---|---:|
58
+ | 1 | C clang | 1.00× |
59
+ | 13 | Java | 3.69× |
60
+ | 18 | Node.js | 6.63× |
61
+ | **19** | **pythonfaster** | **7.04×** |
62
+ | 22 | PyPy | 17.41× |
63
+ | 29 | CPython 3.12 | 55.10× |
64
+
65
+ ### Per-benchmark results (official workloads)
66
+
67
+ All 10 benchmarks pass strict output verification. Apple Silicon M3, Python 3.12.0, strict-mode pre-check enabled (default), fastest of multiple fresh-subprocess runs:
68
+
69
+ | Benchmark | Workload | CPython 3.12 | pythonfaster | Speedup |
70
+ |---|---:|---:|---:|---:|
71
+ | binary_trees | 21 | 43.97s | 0.37s | **117.6×** |
72
+ | spectral_norm | 5,500 | 133.08s | 1.62s | **82.3×** |
73
+ | mandelbrot | 16,000 | 300.58s | 10.83s | **27.8×** |
74
+ | fannkuch_redux | 12 | 373.77s | 21.32s | **17.5×** |
75
+ | nbody | 50,000,000 | 122.78s | 9.61s | **12.8×** |
76
+ | pidigits | 10,000 | 2.33s | 0.40s | **5.8×** |
77
+ | revcomp | 100M stdin | 14.05s | 10.02s | 1.40× |
78
+ | regex_redux | 5M stdin | 12.26s | 9.08s | 1.35× |
79
+ | fasta | 25,000,000 | 21.51s | 17.67s | 1.22× |
80
+ | knucleotide | 25M stdin | 142.02s | 133.01s | 1.07× |
81
+ | | | | **Geometric mean** | **7.82×** |
82
+
83
+ Compute-heavy code gets 5.8×–117.6×. I/O-heavy code (fasta, knucleotide, revcomp) sees modest gains because its hot path already runs inside C extensions of the standard library.
84
+
85
+ ![Per-benchmark comparison](benchmarks/results/current/benchmark_comparison.png)
86
+
87
+ ### Object-intensive workloads
88
+
89
+ Seven class-layout benchmarks (CPython 3.12 vs pythonfaster vs Java on the same programs):
90
+
91
+ | Benchmark | CPython | pythonfaster | Java | Speedup |
92
+ |---|---:|---:|---:|---:|
93
+ | linked_tree | 0.280s | 0.050s | 0.004s | **5.63×** |
94
+ | particle_sim | 0.140s | 0.039s | 0.006s | **3.62×** |
95
+ | typed_attrs | 0.762s | 0.286s | 0.012s | **2.67×** |
96
+ | interp_objects | 0.481s | 0.190s | 0.007s | **2.53×** |
97
+ | banking | 0.335s | 0.142s | 0.007s | **2.36×** |
98
+ | rat_arith | 0.225s | 0.215s | 0.002s | 1.05× |
99
+ | shapes_polymorphism | 0.148s | 0.221s | 0.009s | 0.67× |
100
+
101
+ Geometric mean 2.17×. The `shapes_polymorphism` regression is a known limit: virtual dispatch through non-cdef subclasses defeats method-call lowering, and that code is skipped from optimization — the cost is call-site indirection, not correctness.
102
+
103
+ ## Quick start
104
+
105
+ ```bash
106
+ pip install pythonfaster
107
+ pythonfaster enable
108
+ ```
109
+
110
+ After that, Python processes auto-activate pythonfaster only for modules below a detected project root (a `pyproject.toml`, `pythonfaster.toml`, or `.git` marker in the CWD tree). Disable globally with `pythonfaster disable`, or per-process with `PYTHONFASTER_DISABLE=1`.
111
+
112
+ For explicit per-process activation:
113
+
114
+ ```python
115
+ from pythonfaster import Config, install
116
+
117
+ install(Config(root="."))
118
+ ```
119
+
120
+ ## Requirements
121
+
122
+ - Python 3.10 or newer
123
+ - Cython 3.0 or newer (installed automatically as a package dependency)
124
+ - A working native C/C++ build toolchain compatible with the active Python interpreter (Xcode Command Line Tools on macOS, or GCC/Clang and Python development headers on Linux)
125
+ - A project-root marker: `pyproject.toml`, `pythonfaster.toml`, or `.git`
126
+
127
+ The package is designed for CPython. The cache key includes Python ABI, Cython version, compiler flags, CPU target, source bytes, and strategy-set version.
128
+
129
+ ## Pipeline and safety model
130
+
131
+ ```mermaid
132
+ flowchart TD
133
+ A[import module.py] --> B{module under project root?}
134
+ B -->|no| Z[standard Python import]
135
+ B -->|yes| C[compute cache key]
136
+ C --> D{cached extension?}
137
+ D -->|yes| E[load extension]
138
+ D -->|no| F{compatibility pre-check}
139
+ F -->|unsafe pattern| Z
140
+ F -->|safe| G[conservative AST transforms]
141
+ G --> H{Cython build}
142
+ H -->|transformed build fails| I[retry verbatim source]
143
+ I -->|fails| Z
144
+ H -->|success| E
145
+ I -->|success| E
146
+ E --> J{extension initialization succeeds?}
147
+ J -->|yes| K[accelerated module]
148
+ J -->|no| L[execute original .py and record skip]
149
+ L --> K
150
+ ```
151
+
152
+ The degradation path is intentional:
153
+
154
+ 1. **Compatibility pre-check** skips known CPython/Cython semantic mismatches before compilation.
155
+ 2. **Transform fallback** uses an unchanged `.py` copy if analysis declines or a transform fails.
156
+ 3. **Build fallback** returns control to Python if Cython compilation fails.
157
+ 4. **Runtime fallback** executes the original source, removes the failing artifact, and persistently skips that exact cache key after extension initialization fails.
158
+
159
+ The persistent cache and skip index live under `~/.cache/pythonfaster/<implementation>-<major><minor>/` by default. Set `PYTHONFASTER_CACHE_DIR` to relocate it.
160
+
161
+ ## Optimization scope
162
+
163
+ The transform engine selectively applies optimizations only when its preconditions can be established:
164
+
165
+ - local integer/float/range type inference;
166
+ - cdef-class conversion, typed attributes, and direct method-call lowering;
167
+ - selected numeric-container unboxing;
168
+ - expression-helper inlining and `sum(generator)` loopification;
169
+ - recursive cdef lowering and integer-only loop-invariant `sum` folding.
170
+
171
+ Global Cython directives remain conservative. Per-function directives are injected only by transforms that establish their safety conditions.
172
+
173
+ ## Reproducing the numbers
174
+
175
+ ```bash
176
+ # Development-sized profile; suitable for a quick local check.
177
+ python benchmarks/full_compare.py --runs 3
178
+
179
+ # CLBG reference profile; expensive and may take a long time.
180
+ python benchmarks/full_compare.py --reference-profile --runs 3 --no-resume
181
+
182
+ # Render HTML only from the current JSON snapshots.
183
+ python benchmarks/render_report.py
184
+
185
+ # Object-intensive comparison (the authoritative object benchmark entry point).
186
+ python benchmarks/obj_compare.py
187
+ ```
188
+
189
+ For publication, record macOS/Linux version, CPU, RAM, Python/Cython/compiler versions, compiler flags, exact command, run count, and summary statistic. Do not combine results from separate runs in one ranking.
190
+
191
+ ## Testing
192
+
193
+ ```bash
194
+ # Project regression tests: runtime extension failure must fall back to source.
195
+ python -m pytest -q
196
+
197
+ # CPython-standard-library compatibility probe (requires a CPython test-suite installation).
198
+ python tests/run_cpython_tests.py
199
+ ```
200
+
201
+ `tests/run_cpython_tests.py` and `tests/speed_compare.py` clear the cache for the active interpreter dynamically; they do not assume a specific CPython minor version. The standard-library probe is an integration/compatibility measurement, not a replacement for focused unit tests of individual AST passes.
202
+
203
+ ## Configuration
204
+
205
+ Configuration is loaded in this order (later sources override earlier ones):
206
+
207
+ 1. `[pythonfaster]` in `pythonfaster.toml`, or `[tool.pythonfaster]` in `pyproject.toml`;
208
+ 2. environment variables;
209
+ 3. defaults.
210
+
211
+ | Option | Default | Meaning |
212
+ |---|---:|---|
213
+ | `enabled` | `true` | Master switch |
214
+ | `exclude` | built-in patterns | Additional `fnmatch` paths not to compile |
215
+ | `aggressive` | `false` | Higher-risk transforms (off by default; currently no-op) |
216
+
217
+ Useful environment variables: `PYTHONFASTER_DISABLE=1`, `PYTHONFASTER_STRICT=0|1`, `PYTHONFASTER_VERBOSE=1`, `PYTHONFASTER_CACHE_DIR`, `PYTHONFASTER_MARCH_NATIVE=1`, and `PYTHONFASTER_KEEP_INTERMEDIATE=1`.
218
+
219
+ `PYTHONFASTER_STRICT=1` is the default. It enables all known compatibility guards. Setting it to `0` may improve coverage but accepts known Cython semantic risks. `PYTHONFASTER_MARCH_NATIVE=1` can improve local performance but makes cached artifacts CPU-specific; use it only for a cache that is not shared between different machines.
220
+
221
+ ## Limitations
222
+
223
+ - Compilation adds cold-start cost; it is most appropriate for repeatedly imported or long-running numeric workloads.
224
+ - Python/Cython semantic compatibility is not universal. Unsupported or risky modules deliberately fall back to Python.
225
+ - String- and I/O-bound code often sees limited benefit because its expensive work already occurs in C extensions or the standard library.
226
+ - Native compilation requires a compatible local toolchain; failure to build is non-fatal and falls back to Python.
227
+ - Benchmarks are sensitive to hardware, thermal state, compiler, input size, and cache warmness. Treat checked-in JSON as evidence for its recorded environment only.
228
+
229
+ ## Project layout
230
+
231
+ ```text
232
+ pythonfaster/
233
+ ├── pythonfaster/ # import hook, config, cache, compiler, transforms
234
+ ├── benchmarks/
235
+ │ ├── full_compare.py # multi-runtime CLBG comparison
236
+ │ ├── obj_compare.py # object-intensive comparison
237
+ │ ├── render_report.py # render report from current JSON data
238
+ │ └── results/current/ # latest raw benchmark snapshots and generated report
239
+ ├── tests/
240
+ │ ├── test_runtime_fallback.py
241
+ │ ├── run_cpython_tests.py
242
+ │ └── speed_compare.py
243
+ └── pyproject.toml
244
+ ```
245
+
246
+ ## Publishing to PyPI
247
+
248
+ ### One-time setup
249
+
250
+ ```bash
251
+ pip install build twine
252
+ # or: pip install -e ".[dev]"
253
+ ```
254
+
255
+ Configure PyPI credentials (create an API token at [pypi.org/manage/account](https://pypi.org/manage/account)):
256
+
257
+ ```bash
258
+ # ~/.pypirc
259
+ [pypi]
260
+ username = __token__
261
+ password = pypi-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
262
+ ```
263
+
264
+ ### Build and upload
265
+
266
+ ```bash
267
+ # 1. Clean previous builds
268
+ rm -rf dist/ build/ *.egg-info
269
+
270
+ # 2. Build source distribution + wheel
271
+ python -m build
272
+
273
+ # 3. Verify the package
274
+ python -m twine check dist/*
275
+
276
+ # 4. Upload to Test PyPI first (recommended)
277
+ python -m twine upload --repository testpypi dist/*
278
+
279
+ # 5. Upload to PyPI
280
+ python -m twine upload dist/*
281
+ ```
282
+
283
+ ### Verify the release
284
+
285
+ ```bash
286
+ pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple pythonfaster
287
+ # or for the production release:
288
+ pip install pythonfaster
289
+ ```
290
+
291
+ ### Automated release (GitHub Actions)
292
+
293
+ A sample `.github/workflows/publish.yml` for automatic release on tag push:
294
+
295
+ ```yaml
296
+ name: Publish to PyPI
297
+ on:
298
+ push:
299
+ tags:
300
+ - 'v*'
301
+ jobs:
302
+ publish:
303
+ runs-on: ubuntu-latest
304
+ steps:
305
+ - uses: actions/checkout@v4
306
+ - uses: actions/setup-python@v5
307
+ with:
308
+ python-version: '3.12'
309
+ - run: pip install build twine
310
+ - run: python -m build
311
+ - run: python -m twine upload dist/*
312
+ env:
313
+ TWINE_USERNAME: __token__
314
+ TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
315
+ ```
316
+
317
+ ## License
318
+
319
+ MIT
320
+
321
+ ## Appendix: Full 31-language CLBG ranking
322
+
323
+ <details>
324
+ <summary>Full 31-language ranking with pythonfaster inserted</summary>
325
+
326
+ Calibrated to the official CLBG language ranking (C = 1.00×; the multiplier means "how many times slower than C"). Inserted, pythonfaster jumps from CPython 3.12's 29th place to 19th:
327
+
328
+ | Rank | Language | vs C |
329
+ |---:|---|---:|
330
+ | 1 | C clang | 1.00× |
331
+ | 2 | C++ g++ | 1.12× |
332
+ | 3 | Rust | 1.17× |
333
+ | 4 | Julia | 2.32× |
334
+ | 5 | C# .NET | 2.39× |
335
+ | 6 | Chapel | 2.52× |
336
+ | 7 | Fortran | 2.55× |
337
+ | 8 | Ada 2012 GNAT | 2.89× |
338
+ | 9 | F# .NET | 3.23× |
339
+ | 10 | Go | 3.35× |
340
+ | 11 | Haskell GHC | 3.45× |
341
+ | 12 | Free Pascal | 3.63× |
342
+ | 13 | Java | 3.69× |
343
+ | 14 | OCaml | 3.94× |
344
+ | 15 | Swift | 5.50× |
345
+ | 16 | Lisp SBCL | 5.55× |
346
+ | 17 | Dart | 6.37× |
347
+ | 18 | Node.js | 6.63× |
348
+ | **19** | **pythonfaster** | **7.04×** |
349
+ | 20 | Racket | 7.56× |
350
+ | 21 | PHP | 12.74× |
351
+ | 22 | PyPy | 17.41× |
352
+ | 23 | Pyston | 28.60× |
353
+ | 24 | Erlang | 33.66× |
354
+ | 25 | Ruby | 39.01× |
355
+ | 26 | VW Smalltalk | 41.11× |
356
+ | 27 | CinderX JIT 3.14 | 47.59× |
357
+ | 28 | CPython 3.14 | 53.27× |
358
+ | 29 | CPython 3.12 | 55.10× |
359
+ | 30 | Lua | 61.34× |
360
+ | 31 | Perl | 67.97× |
361
+
362
+ </details>
@@ -0,0 +1,18 @@
1
+ pythonfaster/__init__.py,sha256=u0Xyxtv3lLEJ6f0bp_DSaK1RcUq8K8xttN7h21u4fOU,3247
2
+ pythonfaster/_bootstrap.py,sha256=MfkmZVHfLjG0wOREnD3udQG_e61wuOkZXMDMRbWDF1g,3201
3
+ pythonfaster/_cli.py,sha256=2MQaYmxwDfn1kLRRalKWzOOXTBIVr4OcS1jLeTgrw4M,7650
4
+ pythonfaster/cache.py,sha256=Jkbe9LoDrdPv2W2bXO5-y6XoedIAK7i4h1CcF_ATDOo,9775
5
+ pythonfaster/compiler.py,sha256=rJjcgveDzuHDeLVm259hPIMwXW5ineDj0YDzgD1wLVo,17661
6
+ pythonfaster/config.py,sha256=CvCgLZGmVzB-APYzcL_v5zKoABv-AOcdFzmrSE18NZY,5439
7
+ pythonfaster/hook.py,sha256=aG--lpjFskOayo0Cx-TzvdS-6CzF__h_bgOqW8eghSs,12267
8
+ pythonfaster/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ pythonfaster/transform/__init__.py,sha256=GwWffiI6Ze3sgYPXnywacuGUZ3q_3n5Cwr_83yt-Vd4,426
10
+ pythonfaster/transform/engine.py,sha256=W0o5UvZi7lIQ8gHhj-8xhHi1XuT0awIHcU_REpvB0Us,136448
11
+ pythonfaster/transform/recpass.py,sha256=5u__QyPiCM04aEkpY6U9HBntIZ8uQiSGaJEp1Loz9to,21671
12
+ pythonfaster-1.8.0.data/data/pythonfaster.pth,sha256=w2eHE-eQ_VAJuudKfgS1Aq4DwQ1Bm1I6Zg_QCeR8Z4A,31
13
+ pythonfaster-1.8.0.dist-info/licenses/LICENSE,sha256=9OIM1S0NXXA35XDiUfKYcBJWKzM1MCjVXXujut10OPc,1082
14
+ pythonfaster-1.8.0.dist-info/METADATA,sha256=xvLJlqD4l9IPYta_r44xm4-2dPKSPU7WBbOWuaFq7eg,14570
15
+ pythonfaster-1.8.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
16
+ pythonfaster-1.8.0.dist-info/entry_points.txt,sha256=XEUR31prpv4TA8FZhe0DYV63bhbi9zHEG3udJvP0fYs,56
17
+ pythonfaster-1.8.0.dist-info/top_level.txt,sha256=QGvxM0p5QwPAxekoimNNqispW0L-XNhWn0fWa7wmqqY,13
18
+ pythonfaster-1.8.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pythonfaster = pythonfaster._cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 pythonfaster contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ pythonfaster