1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
|
%global _empty_manifest_terminate_build 0
Name: python-pyjion
Version: 2.0.0
Release: 1
Summary: A JIT compiler wrapper for CPython
License: MIT
URL: https://www.trypyjion.com/
Source0: https://mirrors.nju.edu.cn/pypi/web/packages/29/6a/265e0e7ff3cb4d3d82747afe4ce6ca4646d00d4b90b4e0156d96cda6cebc/pyjion-2.0.0.tar.gz
Requires: python3-rich
Requires: python3-distorm3
%description

Pyjion, a JIT extension for CPython that compiles your Python code into native CIL and executes it using the [.NET 7](https://dotnet.microsoft.com/en-us/download/dotnet/7.0) CLR.
[](https://pyjion.readthedocs.io/en/latest/?badge=latest)
[](https://pypi.org/p/pyjion)
[](https://pepy.tech/project/pyjion)
You can test out Pyjion now at [live.trypyjion.com](https://live.trypyjion.com).
Read the full documentation at [pyjion.readthedocs.io](https://docs.trypyjion.com).
## Installing
```console
$ pip install pyjion
```
## Compiling from source
Prerequisites:
- CPython 3.10
- CMake 3.13 +
- [.NET 7](https://dotnet.microsoft.com/en-us/download/dotnet/7.0)
- scikit-build
```console
$ git clone git@github.com:tonybaloney/pyjion --recurse-submodules
$ cd pyjion
$ python -m pip install .
```
## Using Pyjion
To get started, you need to have .NET installed, with Python 3.10 and the Pyjion package (I also recommend using a virtual environment).
After importing pyjion, enable it by calling `pyjion.enable()` which sets a compilation threshold to 0 (the code only needs to be run once to be compiled by the JIT):
```pycon
>>> import pyjion
>>> pyjion.enable()
```
Any Python code you define or import after enabling pyjion will be JIT compiled. You don't need to execute functions in any special API, its completely transparent:
```pycon
>>> def half(x):
... return x/2
>>> half(2)
1.0
```
Pyjion will have compiled the `half` function into machine code on-the-fly and stored a cached version of that compiled function inside the function object.
You can see some basic stats by running `pyjion.info(f)`, where `f` is the function object:
```pycon
>>> pyjion.info(half)
JitInfo(failed=False, compile_result=<CompilationResult.Success: 1>, compiled=True, optimizations=<OptimizationFlags.InlineFramePushPop|InlineDecref: 10>, pgc=1, run_count=1)
```
You can also execute Pyjion against any script or module:
```console
pyjion my_script.py
```
Or, for an existing Python module:
```console
pyjion -m calendar
```
## Optimization levels
Pyjion has 3 optimization levels, 0 is the lowest and 2 is the highest. By default, Pyjion will compile at level 1.
The level can be changed using the `config()` function:
```python
pyjion.config(level=2)
```
Once you've run your code and tests on level 1, try level 2 to compare performance.
If you have problems, try lowering the level.
## Troubleshooting
### PGC Unboxing error
If you get a `pyjion.PyjionUnboxingError` when running the code, this means that Pyjion optimized a function which had floats, ints or boolean values, but those types have changed in subsequent calls.
To avoid this, you can disable PGC (`pyjion.config(pgc=False)`) or lower the optimization level.
Both options will hurt the overall performance, so if you can, refactor the function to not have general operations for a mixture of types.
## Disassembly
You can see the machine code for the compiled function by disassembling it in the Python REPL.
Pyjion has essentially compiled your small Python function into a small, standalone application.
Install `distorm3` and `rich` first to disassemble x86-64 assembly and run `pyjion.dis.dis_native(f)`:
```pycon
>>> import pyjion.dis
>>> pyjion.dis.dis_native(half)
00000000: PUSH RBP
00000001: MOV RBP, RSP
00000004: PUSH R14
00000006: PUSH RBX
00000007: MOV RBX, RSI
0000000a: MOV R14, [RDI+0x40]
0000000e: CALL 0x1b34
00000013: CMP DWORD [RAX+0x30], 0x0
00000017: JZ 0x31
00000019: CMP QWORD [RAX+0x40], 0x0
0000001e: JZ 0x31
00000020: MOV RDI, RAX
00000023: MOV RSI, RBX
00000026: XOR EDX, EDX
00000028: POP RBX
00000029: POP R14
...
```
The complex logic of converting a portable instruction set into low-level machine instructions is done by .NET's CLR JIT compiler.
All Python code executed after the JIT is enabled will be compiled into native machine code at runtime and cached on disk. For example, to enable the JIT on a simple `app.py` for a Flask web app:
```python
from src import pyjion
pyjion.enable()
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
app.run()
```
## FAQ
### How do you pronounce "Pyjion"?
Like the word "pigeon". @DinoV wanted a name that had something with "Python"
-- the "Py" part -- and something with "JIT" -- the "JI" part -- and have it be
pronounceable.
### How do this compare to
#### [PyPy](http://pypy.org/)?
[PyPy](http://pypy.org/) is an implementation of Python with its own JIT. The
biggest difference compared to Pyjion is that PyPy doesn't support all C extension
modules without modification unless they use [CFFI](https://cffi.readthedocs.org)
or work with the select subset of CPython's C API that PyPy does support.
Pyjion also aims to support many JIT compilers while PyPy only supports their
custom JIT compiler.
#### [Pyston](http://pyston.org)?
[Pyston](http://pyston.org) is an implementation of Python using
[LLVM](http://llvm.org/) as a JIT compiler. Compared to Pyjion, Pyston has
partial CPython C API support but not complete support. Pyston also only
supports LLVM as a JIT compiler.
#### [Numba](http://numba.pydata.org/)?
[Numba](http://numba.pydata.org/) is a JIT compiler for "array-oriented and
math-heavy Python code". This means that Numba is focused on scientific
computing while Pyjion tries to optimize all Python code. Numba also only
supports LLVM.
#### [IronPython](http://ironpython.net/)?
[IronPython](http://ironpython.net/) is an implementation of Python that is
implemented using [.NET](https://microsoft.com/NET). While IronPython tries to
be usable from within .NET, Pyjion does not have a compatibility story with .NET.
This also means IronPython cannot use C extension modules while Pyjion can.
#### [Psyco](http://psyco.sourceforge.net/)?
[Psyco](http://psyco.sourceforge.net/) was a module that monkeypatched CPython
to add a custom JIT compiler. Pyjion wants to introduce a proper C API for
adding a JIT compiler to CPython instead of monkeypatching it. It should be
noted the creator of Psyco went on to be one of the co-founders of PyPy.
#### [Unladen Swallow](https://en.wikipedia.org/wiki/Unladen_Swallow)?
[Unladen Swallow](https://en.wikipedia.org/wiki/Unladen_Swallow) was an attempt
to make LLVM be a JIT compiler for CPython. Unfortunately the project lost
funding before finishing their work after having to spend a large amount of
time fixing issues in LLVM's JIT compiler (which has greatly improved over the
subsequent years).
#### [Nuitka](http://nuitka.net/) and [Shedskin](https://github.com/shedskin/shedskin)?
Both [Nuitka](http://nuitka.net/) and
[Shedskin](https://github.com/shedskin/shedskin) are Python-to-C++ transpilers,
which means they translate Python code into equivalent C++ code. Being a JIT,
Pyjion is not a transpiler.
### Will this ever ship with CPython?
Goal #1 is explicitly to add a C API to CPython to support JIT compilers. There
is no expectation, though, to ship a JIT compiler with CPython. This is because
CPython compiles with nothing more than a C89 compiler, which allows it to run
on many platforms. But adding a JIT compiler to CPython would immediately limit
it to only the platforms that the JIT supports.
### Does this help with using CPython w/ .NET or UWP?
No. Use [Python.NET](http://pythonnet.github.io) if you want integration with Python and .NET 4.
## Code of Conduct
This project has adopted the
[Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the
[Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
or contact [opencode@microsoft.com](mailto:opencode@microsoft.com)
with any additional questions or comments.
# Release notes
## 2.0.0
* Updated to .NET 7
## 1.2.7
* Fix a bug in the native x86_64 disassembler giving an error about compatibility on Windows Intel CPUs
## 1.2.6
* Extend optimizations in `RelWithDebInfo` mode
## 1.2.5
* Changed the `pyjion.config(debug=)` setting to allow True or False (as before), or 0 (Release), 1 (Debug), 2 (ReleaseWithDebugInfo)
## 1.2.4
* Updated to rich 11.0
* Fix a bug in the CIL disassembler for constant double (LDC_R8) opcodes
## 1.2.3
* Unboxed operations won't update frame last instruction since they're unable to raise exceptions (making them faster)
## 1.2.2
* Added `pyjion.dis.flow_graph()` function to get a DOT control flow-graph of CIL basic blocks
* Added `pyjion.dis.cil_instructions()` function to get a list of CIL instructions from a compiled function
* Enable ASAN for Windows (compile-time option)
* CIL compiles to short branch opcodes when target is within 1 byte
* Show effective branch target on CIL disassembly output
## 1.2.1
* Fixes a bug in OPT-12 (method caching) where it would store the incorrect cache address for a global type of subclass. Bug seen in SQLalchemy.
## 1.2.0
* PGC unboxing errors are avoided when functions are called with different argument types to those it was optimized with.
* PGC types will now be inferred across jump statements, for loops and other small scopes, improving performance
* LOAD_METHOD will use cached pointers for builtin types like `dict`, `list`, etc. meaning LOAD_METHOD is faster in many cases
* Dictionary merge operators, `|` and `|=` will assert the return type as dict
* Fixes a crash on Windows when referencing call points or sequence points for a free'd module
* Fixes an issue running `pyjion -m module` with arguments
## 1.1.1
* Fixed a critical bug where recursive functions that use a mutable container type (e.g. list) causes a decref to the wrong object and subsequent crash.
* Fixes a bug on graph generation for recursive functions causing a crash in some situations
* Fixes a bug on method calls, which called the wrong method when the class was copied using `copy.copy()`
* Reduced memory consumption for method calls
## 1.1.0
* Added unboxed integer operations for BINARY_LSHIFT, BINARY_RSHIFT, BINARY_AND, BINARY_OR, BINARY_XOR
* BINARY_MULTIPLY and BINARY_POWER will stay unboxed if the right-hand operator is a constant that won't overflow (e.g. x ** 2)
* Added unboxed UNARY_NOT,UNARY_POSITIVE and UNARY_NEGATIVE operation for float, bool and int types
* Added unboxed UNARY_INVERT for int and bool types
* Added unboxed STORE_SUBSCR for bytearrays
* The types of global variables are profiled at compile-time
* Improved performance of bytearrays, by adding an unboxed bytearray type and unboxed slice operations for bytearrays, yielding unboxed integers
* Fixed a reference count bug with unboxed range iterators
* PGC will now allow an int of value 0 or 1 to be unboxed into a bool
* Unboxing of integers is now more efficient and allows for True to be unboxed into 1 and False into 0
## 1.0.0
* Fix a bug on `pyjion.config()` crashing when called with invalid arguments (#401)
* Update to .NET 6 GA
* LOAD_GLOBAL is faster when neither globals or builtins have changed since compiling, by caching the object address.
* Calls to Python functions are now routed through Vector Call (faster)
* Improved performance of calling builtin types, like int(), str(), etc.
* Calls to C Functions are faster
* Added an OptimisticIntegers optimization to level 2 to inspect integer values and unbox them if they're small
* Abstract value profiler will assert tuples of constant values (e.g. float, int) based on value
* LOAD_ATTR will infer the attribute type of classes using a cached attribute lookup table when optimization `AttrTypeTable` (level 1) is enabled
* Fix a bug that would reset the optimization level to 1 whenever `pyjion.enable()` was called
* Fix a bug that would cause an invalid jump operation and a failed compilation for EXTENDED_ARG jumps which occur in big functions
## 1.0.0 (rc4)
* Added ARM64 for Apple macOS (M1 Silicon). The JIT will emit native ARM64 assembly. Disassembler not supported.
* Added Linux/ARM64 support and a manylinux wheel
* Added Windows/ARM64 support
* All JIT configuration is now set using the `pyjion.config()` function instead of `enable_feature()`/`disable_feature()`
* Fixed a bug where `pyjion.graph()` would cause an exception if graphing was not enabled when the function was compiled
* Added support for the `SETUP_ANNOTATIONS` opcode
* Added support for generators in 3.10
* Fixed a bug in the DUP_TOP_TWO opcode with escaped variables
* UNPACK_SEQUENCE will emit types for constant tuples of string, int and float
* STORE_FAST is now profiled during the probe stage of PGC, leading to drastically improved performance in many cases where unboxed ints and floats can be used
* Added a simple benchmark suite script (`Tests/benchmarks/suite.py`)
* Upgraded scikit-build to 0.12 for native VS2019 support
## 1.0.0 (rc3)
* Updated to .NET 6 RC1
* Added Python 3.10 support
* Experimental `try..except` statements, stacked exception handlers and exception filtering. Disabled by default
* Fixed a bug on LOAD_METHOD not raising an exception immediately if the method could not be resolved
* Remove `enable_tracing()` and `enable_profiling` functions in 3.10 builds. Profiling and tracing is detected on compilation and available via the `.info()` method
* Added support for PEP626 (fast line tracing)
* Extended profiling support for CFunction calls
* PyTrace_RETURN now correctly sends the return value as an argument as per CPython spec
* Fixed a bug causing SEG when range iterators are escaped
## 1.0.0 (rc2)
* BINARY_MULTIPLY and BINARY_POWER will assume the resulting integer is a big integer (not unboxed)
* Introduced two optimizations IntegerUnboxingMultiply and IntegerUnboxingPower which are applied at optimization level 2. Try level two if you work with integers, but at smaller values to see better performance.
* Pyjion will infer that `range(n)` generates integers in iterator to improve unboxing
* LOAD_BUILD_CLASS will infer a function type instead of Any (#42)
* Instruction graphs will include the name of fast locals
* Instruction graph const values are capped to 40 characters
* Added abstract types for all builtins (#339)
* `pyjion.info()` will now return a JitInfo object
* Optimization flags that were applied to a function during compilation are available in `JitInfo.optimizations`
* All optimizations are now runtime flags instead of compile-time features
* Unboxing PGC errors will raise `pyjion.PyjionUnboxingError` (ValueError) instead of ValueError
* Instruction graphs will show conditional branches (in orange)
* Fixed a bug in generators where mixed unboxed/boxed fast locals would yield the wrong values with PGC between the first and second compilation stages
* Fixed a de-optimization that happened in rc1 due to PGC asserting the abstract kind on the profiling phase and then always asserting that integers were big-integers
* Fixed a bug where unboxed locals were decrefing frame locals on yield
* Generators will not unbox fast locals for stability reasons
* Fixed a regression on unboxed integers, caused by PGC values being set as Any
* Assert return types for float object methods (as_integer_ratio, conjugate, is_integer, hex)
## 1.0.0 (rc1)
* Added `pyjion` command-line script to complement the `python -m pyjion` command
* The pyjion CLI has flags for enabling profiling, tracing, optimization level, graphs and debugging
* Unboxing integers that don't fit into `long long` will raise a ValueError.
* Pyjion will mark any values above 1 billion as "big integers" and not escape them to reduce the chance of overflows.
* Floating point `__pow__` with negative values matches all behaviour of CPython
* Raising `0` to a negative power will raise a `ZeroDivisionError`
* PGC no longer uses a reference to probed values, dramatically reducing memory consumption between the first and second compile cycles
* Fixed a bug where `statistics.variance([0, 0, 1])` would raise an assertion error because of an overflow raised in Fraction arithmetic (#326)
* Fixed a bug on calling `sys.settrace(None)` would cause a segmentation fault (#330)
* Fixed a bug on optimized calls to custom types would crash on the 3rd execution because of the way PGC held and released references.
* Refactored Pyjion's test suite to Pytest
* Rewrote the documentation site
* Fixed a bug in the native disassembler printing empty comment lines
* Corrected the type signature of `pyjion.get_offsets()`
* Fixed a bug on changed methods for object (like a global) causing crashes because of the way load_method was optimized (#335)
## 1.0.0 (beta7)
* Added `pyjion.symbols(callable)` API to fetch the dictionary of external call tokens
* Extended the `dis()` and `dis_native()` methods with a flag to not print the program counter (`print_pc=False`)
* Improved the `dis_native()` method to print the name of the method call after the `call` instructions as a line comment
* Fixed a bug in `dis_native()` which showed unresolved sequence points at the top of the printout
* Fixed a bug where `in` (CONTAINS_OP) result wasn't being checked for exceptions and the next operation would segfault if the `in` operation returned an error result.
* The IL in `dis()` is closer in syntax to ILDasm and easier to read
* Added a `pyjion.status()` method to get runtime data on the JIT
* Windows will now observe the `DOTNET_ROOT` and `DOTNET_LIB_PATH` environment variables
## 1.0.0 (beta6)
* Updated to .NET 6 preview 6
* Fixed a bug where `ord()` builtin would return the wrong type (#315)
* `pyjion.dis.dis()` and `pyjion.dis.dis_native()` will show sequence points as comments
* The BINARY_POWER and INPLACE_POWER opcodes will always return a native python long instead of an escaped integer, to avoid overflows
## 1.0.0 (beta5)
* Fixed a bug on large dictionary literals (>100 keys)
* Improved the efficiency of the BUILD_TUPLE, BUILD_LIST, BUILD_CONST_KEY_MAP, and BUILD_SET opcodes
* Fixed a bug with comparison of numpy arrays being unboxed into a boolean instead of staying as an array (#310)
## 1.0.0 (beta4)
* Support for the `yield` keyword and Python generators
## 1.0.0 (beta3)
* Instruction graphs can be enabled with `pyjion.enable_graphs()` and then exported by `pyjion.get_graph(f)`
* Pyjion will raise an ImportError if .NET is missing instead of a system exit
## 1.0.0 (beta2)
* Fast locals can store unboxed values
* Method calls are optimized for known types by asserting the return type, e.g. `str.upper()` returns a string
* Updated to .NET 6 preview 5
* Pyjion can be run using `python -m pyjion <command>`, e.g. `python -m pyjion script.py` or `python -m pyjion -m unittest`
## 1.0.0 (beta1)
* Added unboxing for integers (OPT-16)
* Added unboxing for bool
* Fixed a bug with interned hash maps on Windows
## 1.0.0 (alpha4)
* Added unboxing and escape analysis for floating point objects (OPT-16)
* Removed OPT-8 as it is superseded by OPT-16
## 1.0.0 (alpha3)
* Updated to .NET 6 preview 4
## 1.0.0 (alpha2)
* Debuggable JIT methods can be toggled at runtime using `pyjion.enable_debug()`/`pyjion.disable_debug()`
* Added option for including Python bytecode disassembly in Pyjion disassemble printouts on `pyjion.dis.dis()` and `pyjion.dis.dis_native()`
* Added API `pyjion.get_offsets(callable)` to get the offsets of Python Opcode <> IL offset <> native offset.
* Moved internal representations to fixed width standard types.
## 1.0.0 (alpha1)
* Pyjion uses .NET 6 Preview 3 as the compiler, for Linux and macOS make sure you have installed it first
* Rich comparisons (==, <, >) of floating point numbers are significantly faster (OPT-17)
* All method calls are faster by enforcing vectorcall protocol and inlining anything below 10 arguments (OPT-16)
## 0.15.0
* PGC now observes and optimizes heap-allocated (user-defined) types
* Fixed a crash on certain recursive functions with PGC enabled
## 0.14.1
* Fixed macOS wheel name
## 0.14.0
* LOAD_ATTR is now optimized by for types that implement the tp_getattr by prehashing the names (OPT-15)
* JIT will emit a direct call to LOAD_ATTR tp_getattro/tp_getattr slots for builtin types
* macOS wheels are now compiled with Clang PGO
* PGC will only profile non heap-allocated types (ie not user specified types) as type objects could be deallocated between compilation cycles
* Reduced stack effect during frame calls/function calls
* Improved performance on function calls
* Py_MakePendingCalls will be called every 100 instructions (previously 10), configurable at compile-time through the `EMIT_PENDING_CALL_COUNTER` definition
* Updated to .NET 5.0.5 (5.0.202)
* Fixed a bug in PGC for large functions meaning they wouldn't be optimized
* Implemented PGC for BINARY_SUBSCR (OPT-5)
* Implemented PGC for STORE_SUBSCR (OPT-6)
* Implemented PGC for all inplace and regular binary operators (+, -, / etc) see OPT-13
## 0.13.0
* The compiler will now fail (and default back to CPython) if .NET emits a FAST_FAIL helper
* UNPACK_SEQUENCE is rewritten to be more efficient and use optimized paths for LIST and TUPLE types
* f-string (BUILD_STRING) is rewritten to be more efficient
* UNPACK_EX is rewritten to remove the requirement for dynamic heap allocation (and the stack canary) and leverage .NET compiler's dynamic eval stack
* PGC implemented for UNPACK_SEQUENCE
* PGC implemented for BINARY_SUBSCR
* PGC implemented for CALL_FUNCTION/OPT-14
## 0.12.0
* Added PGC emitter to first compile pass
* Drastically simplified the compilation process, resulting in a smaller call stack and allowing for more recursion (and better performance)
* Added a field to the pyjion.info() dictinary, `compile_result`, indicating cause of compilation failure (if failed), see `AbstractInterpreterResult` for enumerations
* Fixed a bug in pyjion.dump_native/pyjion.dis.dis_native disassembling the wrapper function
* Incompatible functions (those with async, yield keyword) are marked as incompatible early in the compilation process
* Fixed a bug in OPT-13 if the type changed under certain circumstances
* Arguments to a frame are now marked as volatile and requiring type guards for certain optimizations
* Any Python type passed as an argument is now available to be optimized by OPT-13, OPT-12
* Fixed a bug occuring on Linux and Windows in sre_parse._compile which caused a GuardStackException when doing an inline decref operation.
* Added an environment variable DOTNET_LIB_PATH to allow specifying the exact path to libclrjit
## 0.11.0
* Added OPT-13 (OPTIMIZE_TYPESLOT_LOOKUPS) to optimize the type slots for all binary operators and resolve the precedence at compile-time (only for known types)
* Added OPT-14 (OPTIMIZE_FUNCTION_CALLS) to optimize calls to builtin functions
* Optimize all frame locals by determining abstract types on compilation
* Bugfix: Fixed a crash on f-strings with lots (>255) arguments
* Bugfix: Will now skip all functions containing the use of `exec()` as it contains frame globals which are not supported
* Updated to .NET 5.0.3
* Updated the containers to Ubuntu 20
* Added fileobject abstract type
* Added enumerator abstract type
* Added code object abstract type
* Added integration tests for reference leaks for all binary operations (thanks @amaeckelberghe)
* Added module type (thanks @vacowboy75)
## 0.10.0
* Added OPT-12 (OPTIMIZE_BUILTIN_METHOD) to pre-lookup methods for builtin types and bypass LOAD_METHOD (PyObject_GetMethod)
* Optimized LOAD_METHOD to recycle lookups for the same object
* Expanded OPT-8, OPT-9, OPT-11, OPT-12 for nested stacks (e.g. inside expressions)
* Added a frozen set abstract type
## 0.9.0
* Added OPT-11 (OPTIMIZE_BINARY_SLICE) to optimize the BUILD_SLICE and BINARY_SUBSCR operations into a single function when the slice start, stop and step is None or a const number.
* Fixed a bug in the set_optimization_level() being reset (thanks @tetsuo-cpp)
* Added a bytearray abstract value kind (thanks @tetsuo-cpp)
* Added a type abstract value kind (thanks @tetsuo-cpp)
* Optimized the compiled instructions to only update the frame last instruction field on error/exit branch
* Removed the "periodic work" method which was called for every for/while loop and put a function to call Py_MakePendingCalls for every 10th loop
* Added an improvement to the process stage to infer the abstract types of return values to methods of builtin types, e.g. str.encode
* Added a check in dis_native for when the compiled function wasn't compiled (thanks @tetsuo-cpp)
* dis_native will now pretty print the assembly code when the `rich` package is installed (thanks @C4ptainCrunch)
* `pyjion[dis]` is a new package bundled with pystorm3 and rich (thanks @C4ptainCrunch)
## 0.8.0
* Enhanced the process stage of the compiler with new abstract types, iterable, bytearray, codeobject, frozenset, enumerator, file, type and module
* Process stage will assert the abstract return type of any call to a builtin function (e.g. list(), tuple()), which will kick in the optimizations for a broader set of scenarios
* Added OPT-8 (OPTIMIZE_BINARY_FUNCTIONS) to combine 2 sequential binary operations into a single operation. Adds about 15-20% performance gain on PyFloat operations.
* Added OPT-9 (OPTIMIZE_ITERATORS) to inline the FOR_ITER opcode of a listiter (List iterator) into native assembly instructions.
* Added OPT-10 (OPTIMIZE_HASHED_NAMES) to precompute the hashes for LOAD_NAME and LOAD_GLOBAL dictionary lookups
* Fixed a bug where looking up a known hash for a dictionary object (optimized BINARY_SUBSCR) wouldn't raise a KeyError. Seen in #157
## 0.7.0
* Fixed a bug in JUMP_IF_FALSE_OR_POP/JUMP_IF_TRUE_OR_POP opcodes emitting a stack growth, which would cause a stack underflow on subsequent branch checks. JIT will compile a broader range of functions now
* Implemented PEP590 vector calls for methods with 10+ arguments (thanks @tetsuo-cpp)
* Implemented PEP590 vector calls for functions with 10+ arguments
* Fixed a reference leak on method calls with large number of arguments
* Support for tracing of function calls with 10+ arguments
* Disabled OPT-4 as it is causing reference leaks
## 0.6.0
* Added OPT-6 optimization. Frame constants are now used to speed up assignments to lists and dictionaries. STORE_SUBSCR will assert if something is a list, or dict and shortcut
the assignment logic.
* Added OPT-7 optimization. The binary subscript operator is compiled to faster path under a set of circumstances, especially if the index/key is a frame constant. Hashes are precomputed
and indexes for integer constants are converted to native numbers at compile-time.
* The native machine-code disassembler will show the actual position of the JITed code in memory, instead of starting the offset at 0
* The `pyjion.dump_native()` function returns a tuple with bytes, length and position
* Type inferencing has been improved for all inplace and binary operations
* Windows builds from source are fixed for when the user wants to compile against a checkout of .NET
* Implemented FAST_DISPATCH for additional opcodes
* Added a test runner for the CPython regression suite that tests the JIT in isolation
* Fixed a reference leak of (self) for the LOAD_METHOD opcode
* Fixed a reference leak of non C functions being called via Call<N> (CALL_FUNCTION)
* Fixed a bug where (very) large tuples being created via the BUILD_TUPLE opcode would cause an overflow error
* Fixed a bug on BUILD_MAP being called with very large dictionaries caused a fatal error
## 0.5.0
* Added OPT-4 optimization. Frame locals (named variables known at compilation) using the LOAD_FAST, STORE_FAST and DELETE_FAST
opcodes will use native .NET locals instead of using the frame's f_localsplus array.
* Improved performance in LOAD_FAST and STORE_FAST through OPT-4
* Added OPT-5 optimization. Frame push/pop on entry/exit are now inline CIL instructions.
* LOAD_FAST skips unbound local checks when proceeded by a STORE_FAST (i.e. slot is definitely assigned)
## 0.4.0
* Fixed a crash bug where CPython checks recursion depth from ceval state, which may not be set
* Implemented a faster check for recursion depth
* Fixed a bug on LOAD_CLOSURE operator not being set
* Fixed OPT-2 on Windows and Linux
* Fixed a bug where the wrong CIL opcode was being used to subtract values, would throw an overflow error and fail back into EFD.
* Implemented the .NET EE exception handlers for guard stack canaries, overflow errors, and null reference exceptions
* Implemented a more efficient case of ld_i(1)
* Corrected cases of ob_refcnt to use 64-bit signed integers
* No longer print error messages on release code for unimplemented .NET EE methods
* Fixed a bug on the incorrect vtable relative field being set
* Fixed a bug where tracing and profiling would be emitted even when not explicitly enabled
* .NET Exceptions are transferred into Python exceptions at runtime
## 0.3.0
* Added an optimization (OPT-1/OPTIMIZE_IS) to inline the "is"/ "is not" statement into a simple pointer comparison with jump statement. Compiles to inline machine code instead of a method call
* Added an optimization (OPT-2/OPTIMIZE_DECREF) to decrement the refcount without a method call, when the object refcount is >1 and then call _Py_dealloc if the ref count becomes 0. Replaces the previous method call
* Windows now uses the system page size instead of the default value of 1MB
## 0.2.1
* Added support for .NET 5.0.1
* Implemented a CIL modulus emitter
## 0.2.0
* Added support for profiling compiled functions by enabling profiling (`pyjion.enable_profiling()`)
* Added support for profiling C function calls, returns and exceptions
* Implemented a faster call path for functions and methods for 5-10 arguments
* Fixed a bug where the page size defaulted to 0 in the .NET EE, which caused a failed assertion (and fails to compile the function), would fix a large % of functions that previously failed to compile
## 0.1.0
* Added support for debugging compiled functions and modules by enabling tracing (`pyjion.enable_tracing()`)
* Added support for debugging to catch unhandled/handled exceptions at runtime when tracing is enabled
* Added support for opcode-level tracing
* Fixed a bug on executing Pyjion with pydevd (VScode/PyCharm debugger) would cause the Python process to crash because of a doubly-freed code object (#7)
## 0.0.7
* Added a WSGI middleware function to enable Pyjion for Flask and Django (#67)
* Fix a bug on dictionary merging for mapping types incorrectly raising a type error (#66)
## 0.0.6
* Implemented supported for disassembling "large" methods into CIL (#27)
* Added type stubs for the pyjion C extension
* Fix a bug where merging or updating a subclassed dictionary would fail with a type error. (#28)
## 0.0.5
* Fixed a critical bug where method calls with large numbers of arguments, and the argument was a tuple could cause a segmentation fault on GC collection.
* Tested support for IPython REPL
* Fixed a bug where importing pyjion.dis after enabling the JIT would cause a stack overflow
* Has around 50% chance of working and not causing your computer to explode, or worse, segmentation fault
## 0.0.4
* Added a stack probe helper for Linux (will use JIT in more scenarios)
* Enabled support for running unit tests in Linux
* Fixed a bug where JIT would crash when a method call failed because of a bad-lookup
* Implemented helper method redirection for Linux to support PIC compiled symbols
* Has around 35% chance of working and not causing your computer to explode, or worse, segmentation fault
* Improved discovery of .NET libraries on Linux
* Fixed a bug where a garble-named log file would be generated (should be JIT timings log)
## 0.0.3
* Installable bdist_wheel for Ubuntu, Debian, macOS 10.15, 11 (10.16) and Windows x64
* Installable manylinux2014 wheel with clrjit.so bundled in
* Added multithreading/multiprocessing support
* Fixed a bug where the wheel would be broken if there are two distributions of Python 3.9 on the system
* Has around 30% chance of working and not causing your computer to explode, or worse, segmentation fault.
## 0.0.2
* Installable source distribution support for macOS, Windows and (barely) Linux.
## 0.0.1
* It compiles on my machine
%package -n python3-pyjion
Summary: A JIT compiler wrapper for CPython
Provides: python-pyjion
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
BuildRequires: python3-cffi
BuildRequires: gcc
BuildRequires: gdb
%description -n python3-pyjion

Pyjion, a JIT extension for CPython that compiles your Python code into native CIL and executes it using the [.NET 7](https://dotnet.microsoft.com/en-us/download/dotnet/7.0) CLR.
[](https://pyjion.readthedocs.io/en/latest/?badge=latest)
[](https://pypi.org/p/pyjion)
[](https://pepy.tech/project/pyjion)
You can test out Pyjion now at [live.trypyjion.com](https://live.trypyjion.com).
Read the full documentation at [pyjion.readthedocs.io](https://docs.trypyjion.com).
## Installing
```console
$ pip install pyjion
```
## Compiling from source
Prerequisites:
- CPython 3.10
- CMake 3.13 +
- [.NET 7](https://dotnet.microsoft.com/en-us/download/dotnet/7.0)
- scikit-build
```console
$ git clone git@github.com:tonybaloney/pyjion --recurse-submodules
$ cd pyjion
$ python -m pip install .
```
## Using Pyjion
To get started, you need to have .NET installed, with Python 3.10 and the Pyjion package (I also recommend using a virtual environment).
After importing pyjion, enable it by calling `pyjion.enable()` which sets a compilation threshold to 0 (the code only needs to be run once to be compiled by the JIT):
```pycon
>>> import pyjion
>>> pyjion.enable()
```
Any Python code you define or import after enabling pyjion will be JIT compiled. You don't need to execute functions in any special API, its completely transparent:
```pycon
>>> def half(x):
... return x/2
>>> half(2)
1.0
```
Pyjion will have compiled the `half` function into machine code on-the-fly and stored a cached version of that compiled function inside the function object.
You can see some basic stats by running `pyjion.info(f)`, where `f` is the function object:
```pycon
>>> pyjion.info(half)
JitInfo(failed=False, compile_result=<CompilationResult.Success: 1>, compiled=True, optimizations=<OptimizationFlags.InlineFramePushPop|InlineDecref: 10>, pgc=1, run_count=1)
```
You can also execute Pyjion against any script or module:
```console
pyjion my_script.py
```
Or, for an existing Python module:
```console
pyjion -m calendar
```
## Optimization levels
Pyjion has 3 optimization levels, 0 is the lowest and 2 is the highest. By default, Pyjion will compile at level 1.
The level can be changed using the `config()` function:
```python
pyjion.config(level=2)
```
Once you've run your code and tests on level 1, try level 2 to compare performance.
If you have problems, try lowering the level.
## Troubleshooting
### PGC Unboxing error
If you get a `pyjion.PyjionUnboxingError` when running the code, this means that Pyjion optimized a function which had floats, ints or boolean values, but those types have changed in subsequent calls.
To avoid this, you can disable PGC (`pyjion.config(pgc=False)`) or lower the optimization level.
Both options will hurt the overall performance, so if you can, refactor the function to not have general operations for a mixture of types.
## Disassembly
You can see the machine code for the compiled function by disassembling it in the Python REPL.
Pyjion has essentially compiled your small Python function into a small, standalone application.
Install `distorm3` and `rich` first to disassemble x86-64 assembly and run `pyjion.dis.dis_native(f)`:
```pycon
>>> import pyjion.dis
>>> pyjion.dis.dis_native(half)
00000000: PUSH RBP
00000001: MOV RBP, RSP
00000004: PUSH R14
00000006: PUSH RBX
00000007: MOV RBX, RSI
0000000a: MOV R14, [RDI+0x40]
0000000e: CALL 0x1b34
00000013: CMP DWORD [RAX+0x30], 0x0
00000017: JZ 0x31
00000019: CMP QWORD [RAX+0x40], 0x0
0000001e: JZ 0x31
00000020: MOV RDI, RAX
00000023: MOV RSI, RBX
00000026: XOR EDX, EDX
00000028: POP RBX
00000029: POP R14
...
```
The complex logic of converting a portable instruction set into low-level machine instructions is done by .NET's CLR JIT compiler.
All Python code executed after the JIT is enabled will be compiled into native machine code at runtime and cached on disk. For example, to enable the JIT on a simple `app.py` for a Flask web app:
```python
from src import pyjion
pyjion.enable()
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
app.run()
```
## FAQ
### How do you pronounce "Pyjion"?
Like the word "pigeon". @DinoV wanted a name that had something with "Python"
-- the "Py" part -- and something with "JIT" -- the "JI" part -- and have it be
pronounceable.
### How do this compare to
#### [PyPy](http://pypy.org/)?
[PyPy](http://pypy.org/) is an implementation of Python with its own JIT. The
biggest difference compared to Pyjion is that PyPy doesn't support all C extension
modules without modification unless they use [CFFI](https://cffi.readthedocs.org)
or work with the select subset of CPython's C API that PyPy does support.
Pyjion also aims to support many JIT compilers while PyPy only supports their
custom JIT compiler.
#### [Pyston](http://pyston.org)?
[Pyston](http://pyston.org) is an implementation of Python using
[LLVM](http://llvm.org/) as a JIT compiler. Compared to Pyjion, Pyston has
partial CPython C API support but not complete support. Pyston also only
supports LLVM as a JIT compiler.
#### [Numba](http://numba.pydata.org/)?
[Numba](http://numba.pydata.org/) is a JIT compiler for "array-oriented and
math-heavy Python code". This means that Numba is focused on scientific
computing while Pyjion tries to optimize all Python code. Numba also only
supports LLVM.
#### [IronPython](http://ironpython.net/)?
[IronPython](http://ironpython.net/) is an implementation of Python that is
implemented using [.NET](https://microsoft.com/NET). While IronPython tries to
be usable from within .NET, Pyjion does not have a compatibility story with .NET.
This also means IronPython cannot use C extension modules while Pyjion can.
#### [Psyco](http://psyco.sourceforge.net/)?
[Psyco](http://psyco.sourceforge.net/) was a module that monkeypatched CPython
to add a custom JIT compiler. Pyjion wants to introduce a proper C API for
adding a JIT compiler to CPython instead of monkeypatching it. It should be
noted the creator of Psyco went on to be one of the co-founders of PyPy.
#### [Unladen Swallow](https://en.wikipedia.org/wiki/Unladen_Swallow)?
[Unladen Swallow](https://en.wikipedia.org/wiki/Unladen_Swallow) was an attempt
to make LLVM be a JIT compiler for CPython. Unfortunately the project lost
funding before finishing their work after having to spend a large amount of
time fixing issues in LLVM's JIT compiler (which has greatly improved over the
subsequent years).
#### [Nuitka](http://nuitka.net/) and [Shedskin](https://github.com/shedskin/shedskin)?
Both [Nuitka](http://nuitka.net/) and
[Shedskin](https://github.com/shedskin/shedskin) are Python-to-C++ transpilers,
which means they translate Python code into equivalent C++ code. Being a JIT,
Pyjion is not a transpiler.
### Will this ever ship with CPython?
Goal #1 is explicitly to add a C API to CPython to support JIT compilers. There
is no expectation, though, to ship a JIT compiler with CPython. This is because
CPython compiles with nothing more than a C89 compiler, which allows it to run
on many platforms. But adding a JIT compiler to CPython would immediately limit
it to only the platforms that the JIT supports.
### Does this help with using CPython w/ .NET or UWP?
No. Use [Python.NET](http://pythonnet.github.io) if you want integration with Python and .NET 4.
## Code of Conduct
This project has adopted the
[Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the
[Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
or contact [opencode@microsoft.com](mailto:opencode@microsoft.com)
with any additional questions or comments.
# Release notes
## 2.0.0
* Updated to .NET 7
## 1.2.7
* Fix a bug in the native x86_64 disassembler giving an error about compatibility on Windows Intel CPUs
## 1.2.6
* Extend optimizations in `RelWithDebInfo` mode
## 1.2.5
* Changed the `pyjion.config(debug=)` setting to allow True or False (as before), or 0 (Release), 1 (Debug), 2 (ReleaseWithDebugInfo)
## 1.2.4
* Updated to rich 11.0
* Fix a bug in the CIL disassembler for constant double (LDC_R8) opcodes
## 1.2.3
* Unboxed operations won't update frame last instruction since they're unable to raise exceptions (making them faster)
## 1.2.2
* Added `pyjion.dis.flow_graph()` function to get a DOT control flow-graph of CIL basic blocks
* Added `pyjion.dis.cil_instructions()` function to get a list of CIL instructions from a compiled function
* Enable ASAN for Windows (compile-time option)
* CIL compiles to short branch opcodes when target is within 1 byte
* Show effective branch target on CIL disassembly output
## 1.2.1
* Fixes a bug in OPT-12 (method caching) where it would store the incorrect cache address for a global type of subclass. Bug seen in SQLalchemy.
## 1.2.0
* PGC unboxing errors are avoided when functions are called with different argument types to those it was optimized with.
* PGC types will now be inferred across jump statements, for loops and other small scopes, improving performance
* LOAD_METHOD will use cached pointers for builtin types like `dict`, `list`, etc. meaning LOAD_METHOD is faster in many cases
* Dictionary merge operators, `|` and `|=` will assert the return type as dict
* Fixes a crash on Windows when referencing call points or sequence points for a free'd module
* Fixes an issue running `pyjion -m module` with arguments
## 1.1.1
* Fixed a critical bug where recursive functions that use a mutable container type (e.g. list) causes a decref to the wrong object and subsequent crash.
* Fixes a bug on graph generation for recursive functions causing a crash in some situations
* Fixes a bug on method calls, which called the wrong method when the class was copied using `copy.copy()`
* Reduced memory consumption for method calls
## 1.1.0
* Added unboxed integer operations for BINARY_LSHIFT, BINARY_RSHIFT, BINARY_AND, BINARY_OR, BINARY_XOR
* BINARY_MULTIPLY and BINARY_POWER will stay unboxed if the right-hand operator is a constant that won't overflow (e.g. x ** 2)
* Added unboxed UNARY_NOT,UNARY_POSITIVE and UNARY_NEGATIVE operation for float, bool and int types
* Added unboxed UNARY_INVERT for int and bool types
* Added unboxed STORE_SUBSCR for bytearrays
* The types of global variables are profiled at compile-time
* Improved performance of bytearrays, by adding an unboxed bytearray type and unboxed slice operations for bytearrays, yielding unboxed integers
* Fixed a reference count bug with unboxed range iterators
* PGC will now allow an int of value 0 or 1 to be unboxed into a bool
* Unboxing of integers is now more efficient and allows for True to be unboxed into 1 and False into 0
## 1.0.0
* Fix a bug on `pyjion.config()` crashing when called with invalid arguments (#401)
* Update to .NET 6 GA
* LOAD_GLOBAL is faster when neither globals or builtins have changed since compiling, by caching the object address.
* Calls to Python functions are now routed through Vector Call (faster)
* Improved performance of calling builtin types, like int(), str(), etc.
* Calls to C Functions are faster
* Added an OptimisticIntegers optimization to level 2 to inspect integer values and unbox them if they're small
* Abstract value profiler will assert tuples of constant values (e.g. float, int) based on value
* LOAD_ATTR will infer the attribute type of classes using a cached attribute lookup table when optimization `AttrTypeTable` (level 1) is enabled
* Fix a bug that would reset the optimization level to 1 whenever `pyjion.enable()` was called
* Fix a bug that would cause an invalid jump operation and a failed compilation for EXTENDED_ARG jumps which occur in big functions
## 1.0.0 (rc4)
* Added ARM64 for Apple macOS (M1 Silicon). The JIT will emit native ARM64 assembly. Disassembler not supported.
* Added Linux/ARM64 support and a manylinux wheel
* Added Windows/ARM64 support
* All JIT configuration is now set using the `pyjion.config()` function instead of `enable_feature()`/`disable_feature()`
* Fixed a bug where `pyjion.graph()` would cause an exception if graphing was not enabled when the function was compiled
* Added support for the `SETUP_ANNOTATIONS` opcode
* Added support for generators in 3.10
* Fixed a bug in the DUP_TOP_TWO opcode with escaped variables
* UNPACK_SEQUENCE will emit types for constant tuples of string, int and float
* STORE_FAST is now profiled during the probe stage of PGC, leading to drastically improved performance in many cases where unboxed ints and floats can be used
* Added a simple benchmark suite script (`Tests/benchmarks/suite.py`)
* Upgraded scikit-build to 0.12 for native VS2019 support
## 1.0.0 (rc3)
* Updated to .NET 6 RC1
* Added Python 3.10 support
* Experimental `try..except` statements, stacked exception handlers and exception filtering. Disabled by default
* Fixed a bug on LOAD_METHOD not raising an exception immediately if the method could not be resolved
* Remove `enable_tracing()` and `enable_profiling` functions in 3.10 builds. Profiling and tracing is detected on compilation and available via the `.info()` method
* Added support for PEP626 (fast line tracing)
* Extended profiling support for CFunction calls
* PyTrace_RETURN now correctly sends the return value as an argument as per CPython spec
* Fixed a bug causing SEG when range iterators are escaped
## 1.0.0 (rc2)
* BINARY_MULTIPLY and BINARY_POWER will assume the resulting integer is a big integer (not unboxed)
* Introduced two optimizations IntegerUnboxingMultiply and IntegerUnboxingPower which are applied at optimization level 2. Try level two if you work with integers, but at smaller values to see better performance.
* Pyjion will infer that `range(n)` generates integers in iterator to improve unboxing
* LOAD_BUILD_CLASS will infer a function type instead of Any (#42)
* Instruction graphs will include the name of fast locals
* Instruction graph const values are capped to 40 characters
* Added abstract types for all builtins (#339)
* `pyjion.info()` will now return a JitInfo object
* Optimization flags that were applied to a function during compilation are available in `JitInfo.optimizations`
* All optimizations are now runtime flags instead of compile-time features
* Unboxing PGC errors will raise `pyjion.PyjionUnboxingError` (ValueError) instead of ValueError
* Instruction graphs will show conditional branches (in orange)
* Fixed a bug in generators where mixed unboxed/boxed fast locals would yield the wrong values with PGC between the first and second compilation stages
* Fixed a de-optimization that happened in rc1 due to PGC asserting the abstract kind on the profiling phase and then always asserting that integers were big-integers
* Fixed a bug where unboxed locals were decrefing frame locals on yield
* Generators will not unbox fast locals for stability reasons
* Fixed a regression on unboxed integers, caused by PGC values being set as Any
* Assert return types for float object methods (as_integer_ratio, conjugate, is_integer, hex)
## 1.0.0 (rc1)
* Added `pyjion` command-line script to complement the `python -m pyjion` command
* The pyjion CLI has flags for enabling profiling, tracing, optimization level, graphs and debugging
* Unboxing integers that don't fit into `long long` will raise a ValueError.
* Pyjion will mark any values above 1 billion as "big integers" and not escape them to reduce the chance of overflows.
* Floating point `__pow__` with negative values matches all behaviour of CPython
* Raising `0` to a negative power will raise a `ZeroDivisionError`
* PGC no longer uses a reference to probed values, dramatically reducing memory consumption between the first and second compile cycles
* Fixed a bug where `statistics.variance([0, 0, 1])` would raise an assertion error because of an overflow raised in Fraction arithmetic (#326)
* Fixed a bug on calling `sys.settrace(None)` would cause a segmentation fault (#330)
* Fixed a bug on optimized calls to custom types would crash on the 3rd execution because of the way PGC held and released references.
* Refactored Pyjion's test suite to Pytest
* Rewrote the documentation site
* Fixed a bug in the native disassembler printing empty comment lines
* Corrected the type signature of `pyjion.get_offsets()`
* Fixed a bug on changed methods for object (like a global) causing crashes because of the way load_method was optimized (#335)
## 1.0.0 (beta7)
* Added `pyjion.symbols(callable)` API to fetch the dictionary of external call tokens
* Extended the `dis()` and `dis_native()` methods with a flag to not print the program counter (`print_pc=False`)
* Improved the `dis_native()` method to print the name of the method call after the `call` instructions as a line comment
* Fixed a bug in `dis_native()` which showed unresolved sequence points at the top of the printout
* Fixed a bug where `in` (CONTAINS_OP) result wasn't being checked for exceptions and the next operation would segfault if the `in` operation returned an error result.
* The IL in `dis()` is closer in syntax to ILDasm and easier to read
* Added a `pyjion.status()` method to get runtime data on the JIT
* Windows will now observe the `DOTNET_ROOT` and `DOTNET_LIB_PATH` environment variables
## 1.0.0 (beta6)
* Updated to .NET 6 preview 6
* Fixed a bug where `ord()` builtin would return the wrong type (#315)
* `pyjion.dis.dis()` and `pyjion.dis.dis_native()` will show sequence points as comments
* The BINARY_POWER and INPLACE_POWER opcodes will always return a native python long instead of an escaped integer, to avoid overflows
## 1.0.0 (beta5)
* Fixed a bug on large dictionary literals (>100 keys)
* Improved the efficiency of the BUILD_TUPLE, BUILD_LIST, BUILD_CONST_KEY_MAP, and BUILD_SET opcodes
* Fixed a bug with comparison of numpy arrays being unboxed into a boolean instead of staying as an array (#310)
## 1.0.0 (beta4)
* Support for the `yield` keyword and Python generators
## 1.0.0 (beta3)
* Instruction graphs can be enabled with `pyjion.enable_graphs()` and then exported by `pyjion.get_graph(f)`
* Pyjion will raise an ImportError if .NET is missing instead of a system exit
## 1.0.0 (beta2)
* Fast locals can store unboxed values
* Method calls are optimized for known types by asserting the return type, e.g. `str.upper()` returns a string
* Updated to .NET 6 preview 5
* Pyjion can be run using `python -m pyjion <command>`, e.g. `python -m pyjion script.py` or `python -m pyjion -m unittest`
## 1.0.0 (beta1)
* Added unboxing for integers (OPT-16)
* Added unboxing for bool
* Fixed a bug with interned hash maps on Windows
## 1.0.0 (alpha4)
* Added unboxing and escape analysis for floating point objects (OPT-16)
* Removed OPT-8 as it is superseded by OPT-16
## 1.0.0 (alpha3)
* Updated to .NET 6 preview 4
## 1.0.0 (alpha2)
* Debuggable JIT methods can be toggled at runtime using `pyjion.enable_debug()`/`pyjion.disable_debug()`
* Added option for including Python bytecode disassembly in Pyjion disassemble printouts on `pyjion.dis.dis()` and `pyjion.dis.dis_native()`
* Added API `pyjion.get_offsets(callable)` to get the offsets of Python Opcode <> IL offset <> native offset.
* Moved internal representations to fixed width standard types.
## 1.0.0 (alpha1)
* Pyjion uses .NET 6 Preview 3 as the compiler, for Linux and macOS make sure you have installed it first
* Rich comparisons (==, <, >) of floating point numbers are significantly faster (OPT-17)
* All method calls are faster by enforcing vectorcall protocol and inlining anything below 10 arguments (OPT-16)
## 0.15.0
* PGC now observes and optimizes heap-allocated (user-defined) types
* Fixed a crash on certain recursive functions with PGC enabled
## 0.14.1
* Fixed macOS wheel name
## 0.14.0
* LOAD_ATTR is now optimized by for types that implement the tp_getattr by prehashing the names (OPT-15)
* JIT will emit a direct call to LOAD_ATTR tp_getattro/tp_getattr slots for builtin types
* macOS wheels are now compiled with Clang PGO
* PGC will only profile non heap-allocated types (ie not user specified types) as type objects could be deallocated between compilation cycles
* Reduced stack effect during frame calls/function calls
* Improved performance on function calls
* Py_MakePendingCalls will be called every 100 instructions (previously 10), configurable at compile-time through the `EMIT_PENDING_CALL_COUNTER` definition
* Updated to .NET 5.0.5 (5.0.202)
* Fixed a bug in PGC for large functions meaning they wouldn't be optimized
* Implemented PGC for BINARY_SUBSCR (OPT-5)
* Implemented PGC for STORE_SUBSCR (OPT-6)
* Implemented PGC for all inplace and regular binary operators (+, -, / etc) see OPT-13
## 0.13.0
* The compiler will now fail (and default back to CPython) if .NET emits a FAST_FAIL helper
* UNPACK_SEQUENCE is rewritten to be more efficient and use optimized paths for LIST and TUPLE types
* f-string (BUILD_STRING) is rewritten to be more efficient
* UNPACK_EX is rewritten to remove the requirement for dynamic heap allocation (and the stack canary) and leverage .NET compiler's dynamic eval stack
* PGC implemented for UNPACK_SEQUENCE
* PGC implemented for BINARY_SUBSCR
* PGC implemented for CALL_FUNCTION/OPT-14
## 0.12.0
* Added PGC emitter to first compile pass
* Drastically simplified the compilation process, resulting in a smaller call stack and allowing for more recursion (and better performance)
* Added a field to the pyjion.info() dictinary, `compile_result`, indicating cause of compilation failure (if failed), see `AbstractInterpreterResult` for enumerations
* Fixed a bug in pyjion.dump_native/pyjion.dis.dis_native disassembling the wrapper function
* Incompatible functions (those with async, yield keyword) are marked as incompatible early in the compilation process
* Fixed a bug in OPT-13 if the type changed under certain circumstances
* Arguments to a frame are now marked as volatile and requiring type guards for certain optimizations
* Any Python type passed as an argument is now available to be optimized by OPT-13, OPT-12
* Fixed a bug occuring on Linux and Windows in sre_parse._compile which caused a GuardStackException when doing an inline decref operation.
* Added an environment variable DOTNET_LIB_PATH to allow specifying the exact path to libclrjit
## 0.11.0
* Added OPT-13 (OPTIMIZE_TYPESLOT_LOOKUPS) to optimize the type slots for all binary operators and resolve the precedence at compile-time (only for known types)
* Added OPT-14 (OPTIMIZE_FUNCTION_CALLS) to optimize calls to builtin functions
* Optimize all frame locals by determining abstract types on compilation
* Bugfix: Fixed a crash on f-strings with lots (>255) arguments
* Bugfix: Will now skip all functions containing the use of `exec()` as it contains frame globals which are not supported
* Updated to .NET 5.0.3
* Updated the containers to Ubuntu 20
* Added fileobject abstract type
* Added enumerator abstract type
* Added code object abstract type
* Added integration tests for reference leaks for all binary operations (thanks @amaeckelberghe)
* Added module type (thanks @vacowboy75)
## 0.10.0
* Added OPT-12 (OPTIMIZE_BUILTIN_METHOD) to pre-lookup methods for builtin types and bypass LOAD_METHOD (PyObject_GetMethod)
* Optimized LOAD_METHOD to recycle lookups for the same object
* Expanded OPT-8, OPT-9, OPT-11, OPT-12 for nested stacks (e.g. inside expressions)
* Added a frozen set abstract type
## 0.9.0
* Added OPT-11 (OPTIMIZE_BINARY_SLICE) to optimize the BUILD_SLICE and BINARY_SUBSCR operations into a single function when the slice start, stop and step is None or a const number.
* Fixed a bug in the set_optimization_level() being reset (thanks @tetsuo-cpp)
* Added a bytearray abstract value kind (thanks @tetsuo-cpp)
* Added a type abstract value kind (thanks @tetsuo-cpp)
* Optimized the compiled instructions to only update the frame last instruction field on error/exit branch
* Removed the "periodic work" method which was called for every for/while loop and put a function to call Py_MakePendingCalls for every 10th loop
* Added an improvement to the process stage to infer the abstract types of return values to methods of builtin types, e.g. str.encode
* Added a check in dis_native for when the compiled function wasn't compiled (thanks @tetsuo-cpp)
* dis_native will now pretty print the assembly code when the `rich` package is installed (thanks @C4ptainCrunch)
* `pyjion[dis]` is a new package bundled with pystorm3 and rich (thanks @C4ptainCrunch)
## 0.8.0
* Enhanced the process stage of the compiler with new abstract types, iterable, bytearray, codeobject, frozenset, enumerator, file, type and module
* Process stage will assert the abstract return type of any call to a builtin function (e.g. list(), tuple()), which will kick in the optimizations for a broader set of scenarios
* Added OPT-8 (OPTIMIZE_BINARY_FUNCTIONS) to combine 2 sequential binary operations into a single operation. Adds about 15-20% performance gain on PyFloat operations.
* Added OPT-9 (OPTIMIZE_ITERATORS) to inline the FOR_ITER opcode of a listiter (List iterator) into native assembly instructions.
* Added OPT-10 (OPTIMIZE_HASHED_NAMES) to precompute the hashes for LOAD_NAME and LOAD_GLOBAL dictionary lookups
* Fixed a bug where looking up a known hash for a dictionary object (optimized BINARY_SUBSCR) wouldn't raise a KeyError. Seen in #157
## 0.7.0
* Fixed a bug in JUMP_IF_FALSE_OR_POP/JUMP_IF_TRUE_OR_POP opcodes emitting a stack growth, which would cause a stack underflow on subsequent branch checks. JIT will compile a broader range of functions now
* Implemented PEP590 vector calls for methods with 10+ arguments (thanks @tetsuo-cpp)
* Implemented PEP590 vector calls for functions with 10+ arguments
* Fixed a reference leak on method calls with large number of arguments
* Support for tracing of function calls with 10+ arguments
* Disabled OPT-4 as it is causing reference leaks
## 0.6.0
* Added OPT-6 optimization. Frame constants are now used to speed up assignments to lists and dictionaries. STORE_SUBSCR will assert if something is a list, or dict and shortcut
the assignment logic.
* Added OPT-7 optimization. The binary subscript operator is compiled to faster path under a set of circumstances, especially if the index/key is a frame constant. Hashes are precomputed
and indexes for integer constants are converted to native numbers at compile-time.
* The native machine-code disassembler will show the actual position of the JITed code in memory, instead of starting the offset at 0
* The `pyjion.dump_native()` function returns a tuple with bytes, length and position
* Type inferencing has been improved for all inplace and binary operations
* Windows builds from source are fixed for when the user wants to compile against a checkout of .NET
* Implemented FAST_DISPATCH for additional opcodes
* Added a test runner for the CPython regression suite that tests the JIT in isolation
* Fixed a reference leak of (self) for the LOAD_METHOD opcode
* Fixed a reference leak of non C functions being called via Call<N> (CALL_FUNCTION)
* Fixed a bug where (very) large tuples being created via the BUILD_TUPLE opcode would cause an overflow error
* Fixed a bug on BUILD_MAP being called with very large dictionaries caused a fatal error
## 0.5.0
* Added OPT-4 optimization. Frame locals (named variables known at compilation) using the LOAD_FAST, STORE_FAST and DELETE_FAST
opcodes will use native .NET locals instead of using the frame's f_localsplus array.
* Improved performance in LOAD_FAST and STORE_FAST through OPT-4
* Added OPT-5 optimization. Frame push/pop on entry/exit are now inline CIL instructions.
* LOAD_FAST skips unbound local checks when proceeded by a STORE_FAST (i.e. slot is definitely assigned)
## 0.4.0
* Fixed a crash bug where CPython checks recursion depth from ceval state, which may not be set
* Implemented a faster check for recursion depth
* Fixed a bug on LOAD_CLOSURE operator not being set
* Fixed OPT-2 on Windows and Linux
* Fixed a bug where the wrong CIL opcode was being used to subtract values, would throw an overflow error and fail back into EFD.
* Implemented the .NET EE exception handlers for guard stack canaries, overflow errors, and null reference exceptions
* Implemented a more efficient case of ld_i(1)
* Corrected cases of ob_refcnt to use 64-bit signed integers
* No longer print error messages on release code for unimplemented .NET EE methods
* Fixed a bug on the incorrect vtable relative field being set
* Fixed a bug where tracing and profiling would be emitted even when not explicitly enabled
* .NET Exceptions are transferred into Python exceptions at runtime
## 0.3.0
* Added an optimization (OPT-1/OPTIMIZE_IS) to inline the "is"/ "is not" statement into a simple pointer comparison with jump statement. Compiles to inline machine code instead of a method call
* Added an optimization (OPT-2/OPTIMIZE_DECREF) to decrement the refcount without a method call, when the object refcount is >1 and then call _Py_dealloc if the ref count becomes 0. Replaces the previous method call
* Windows now uses the system page size instead of the default value of 1MB
## 0.2.1
* Added support for .NET 5.0.1
* Implemented a CIL modulus emitter
## 0.2.0
* Added support for profiling compiled functions by enabling profiling (`pyjion.enable_profiling()`)
* Added support for profiling C function calls, returns and exceptions
* Implemented a faster call path for functions and methods for 5-10 arguments
* Fixed a bug where the page size defaulted to 0 in the .NET EE, which caused a failed assertion (and fails to compile the function), would fix a large % of functions that previously failed to compile
## 0.1.0
* Added support for debugging compiled functions and modules by enabling tracing (`pyjion.enable_tracing()`)
* Added support for debugging to catch unhandled/handled exceptions at runtime when tracing is enabled
* Added support for opcode-level tracing
* Fixed a bug on executing Pyjion with pydevd (VScode/PyCharm debugger) would cause the Python process to crash because of a doubly-freed code object (#7)
## 0.0.7
* Added a WSGI middleware function to enable Pyjion for Flask and Django (#67)
* Fix a bug on dictionary merging for mapping types incorrectly raising a type error (#66)
## 0.0.6
* Implemented supported for disassembling "large" methods into CIL (#27)
* Added type stubs for the pyjion C extension
* Fix a bug where merging or updating a subclassed dictionary would fail with a type error. (#28)
## 0.0.5
* Fixed a critical bug where method calls with large numbers of arguments, and the argument was a tuple could cause a segmentation fault on GC collection.
* Tested support for IPython REPL
* Fixed a bug where importing pyjion.dis after enabling the JIT would cause a stack overflow
* Has around 50% chance of working and not causing your computer to explode, or worse, segmentation fault
## 0.0.4
* Added a stack probe helper for Linux (will use JIT in more scenarios)
* Enabled support for running unit tests in Linux
* Fixed a bug where JIT would crash when a method call failed because of a bad-lookup
* Implemented helper method redirection for Linux to support PIC compiled symbols
* Has around 35% chance of working and not causing your computer to explode, or worse, segmentation fault
* Improved discovery of .NET libraries on Linux
* Fixed a bug where a garble-named log file would be generated (should be JIT timings log)
## 0.0.3
* Installable bdist_wheel for Ubuntu, Debian, macOS 10.15, 11 (10.16) and Windows x64
* Installable manylinux2014 wheel with clrjit.so bundled in
* Added multithreading/multiprocessing support
* Fixed a bug where the wheel would be broken if there are two distributions of Python 3.9 on the system
* Has around 30% chance of working and not causing your computer to explode, or worse, segmentation fault.
## 0.0.2
* Installable source distribution support for macOS, Windows and (barely) Linux.
## 0.0.1
* It compiles on my machine
%package help
Summary: Development documents and examples for pyjion
Provides: python3-pyjion-doc
%description help

Pyjion, a JIT extension for CPython that compiles your Python code into native CIL and executes it using the [.NET 7](https://dotnet.microsoft.com/en-us/download/dotnet/7.0) CLR.
[](https://pyjion.readthedocs.io/en/latest/?badge=latest)
[](https://pypi.org/p/pyjion)
[](https://pepy.tech/project/pyjion)
You can test out Pyjion now at [live.trypyjion.com](https://live.trypyjion.com).
Read the full documentation at [pyjion.readthedocs.io](https://docs.trypyjion.com).
## Installing
```console
$ pip install pyjion
```
## Compiling from source
Prerequisites:
- CPython 3.10
- CMake 3.13 +
- [.NET 7](https://dotnet.microsoft.com/en-us/download/dotnet/7.0)
- scikit-build
```console
$ git clone git@github.com:tonybaloney/pyjion --recurse-submodules
$ cd pyjion
$ python -m pip install .
```
## Using Pyjion
To get started, you need to have .NET installed, with Python 3.10 and the Pyjion package (I also recommend using a virtual environment).
After importing pyjion, enable it by calling `pyjion.enable()` which sets a compilation threshold to 0 (the code only needs to be run once to be compiled by the JIT):
```pycon
>>> import pyjion
>>> pyjion.enable()
```
Any Python code you define or import after enabling pyjion will be JIT compiled. You don't need to execute functions in any special API, its completely transparent:
```pycon
>>> def half(x):
... return x/2
>>> half(2)
1.0
```
Pyjion will have compiled the `half` function into machine code on-the-fly and stored a cached version of that compiled function inside the function object.
You can see some basic stats by running `pyjion.info(f)`, where `f` is the function object:
```pycon
>>> pyjion.info(half)
JitInfo(failed=False, compile_result=<CompilationResult.Success: 1>, compiled=True, optimizations=<OptimizationFlags.InlineFramePushPop|InlineDecref: 10>, pgc=1, run_count=1)
```
You can also execute Pyjion against any script or module:
```console
pyjion my_script.py
```
Or, for an existing Python module:
```console
pyjion -m calendar
```
## Optimization levels
Pyjion has 3 optimization levels, 0 is the lowest and 2 is the highest. By default, Pyjion will compile at level 1.
The level can be changed using the `config()` function:
```python
pyjion.config(level=2)
```
Once you've run your code and tests on level 1, try level 2 to compare performance.
If you have problems, try lowering the level.
## Troubleshooting
### PGC Unboxing error
If you get a `pyjion.PyjionUnboxingError` when running the code, this means that Pyjion optimized a function which had floats, ints or boolean values, but those types have changed in subsequent calls.
To avoid this, you can disable PGC (`pyjion.config(pgc=False)`) or lower the optimization level.
Both options will hurt the overall performance, so if you can, refactor the function to not have general operations for a mixture of types.
## Disassembly
You can see the machine code for the compiled function by disassembling it in the Python REPL.
Pyjion has essentially compiled your small Python function into a small, standalone application.
Install `distorm3` and `rich` first to disassemble x86-64 assembly and run `pyjion.dis.dis_native(f)`:
```pycon
>>> import pyjion.dis
>>> pyjion.dis.dis_native(half)
00000000: PUSH RBP
00000001: MOV RBP, RSP
00000004: PUSH R14
00000006: PUSH RBX
00000007: MOV RBX, RSI
0000000a: MOV R14, [RDI+0x40]
0000000e: CALL 0x1b34
00000013: CMP DWORD [RAX+0x30], 0x0
00000017: JZ 0x31
00000019: CMP QWORD [RAX+0x40], 0x0
0000001e: JZ 0x31
00000020: MOV RDI, RAX
00000023: MOV RSI, RBX
00000026: XOR EDX, EDX
00000028: POP RBX
00000029: POP R14
...
```
The complex logic of converting a portable instruction set into low-level machine instructions is done by .NET's CLR JIT compiler.
All Python code executed after the JIT is enabled will be compiled into native machine code at runtime and cached on disk. For example, to enable the JIT on a simple `app.py` for a Flask web app:
```python
from src import pyjion
pyjion.enable()
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
app.run()
```
## FAQ
### How do you pronounce "Pyjion"?
Like the word "pigeon". @DinoV wanted a name that had something with "Python"
-- the "Py" part -- and something with "JIT" -- the "JI" part -- and have it be
pronounceable.
### How do this compare to
#### [PyPy](http://pypy.org/)?
[PyPy](http://pypy.org/) is an implementation of Python with its own JIT. The
biggest difference compared to Pyjion is that PyPy doesn't support all C extension
modules without modification unless they use [CFFI](https://cffi.readthedocs.org)
or work with the select subset of CPython's C API that PyPy does support.
Pyjion also aims to support many JIT compilers while PyPy only supports their
custom JIT compiler.
#### [Pyston](http://pyston.org)?
[Pyston](http://pyston.org) is an implementation of Python using
[LLVM](http://llvm.org/) as a JIT compiler. Compared to Pyjion, Pyston has
partial CPython C API support but not complete support. Pyston also only
supports LLVM as a JIT compiler.
#### [Numba](http://numba.pydata.org/)?
[Numba](http://numba.pydata.org/) is a JIT compiler for "array-oriented and
math-heavy Python code". This means that Numba is focused on scientific
computing while Pyjion tries to optimize all Python code. Numba also only
supports LLVM.
#### [IronPython](http://ironpython.net/)?
[IronPython](http://ironpython.net/) is an implementation of Python that is
implemented using [.NET](https://microsoft.com/NET). While IronPython tries to
be usable from within .NET, Pyjion does not have a compatibility story with .NET.
This also means IronPython cannot use C extension modules while Pyjion can.
#### [Psyco](http://psyco.sourceforge.net/)?
[Psyco](http://psyco.sourceforge.net/) was a module that monkeypatched CPython
to add a custom JIT compiler. Pyjion wants to introduce a proper C API for
adding a JIT compiler to CPython instead of monkeypatching it. It should be
noted the creator of Psyco went on to be one of the co-founders of PyPy.
#### [Unladen Swallow](https://en.wikipedia.org/wiki/Unladen_Swallow)?
[Unladen Swallow](https://en.wikipedia.org/wiki/Unladen_Swallow) was an attempt
to make LLVM be a JIT compiler for CPython. Unfortunately the project lost
funding before finishing their work after having to spend a large amount of
time fixing issues in LLVM's JIT compiler (which has greatly improved over the
subsequent years).
#### [Nuitka](http://nuitka.net/) and [Shedskin](https://github.com/shedskin/shedskin)?
Both [Nuitka](http://nuitka.net/) and
[Shedskin](https://github.com/shedskin/shedskin) are Python-to-C++ transpilers,
which means they translate Python code into equivalent C++ code. Being a JIT,
Pyjion is not a transpiler.
### Will this ever ship with CPython?
Goal #1 is explicitly to add a C API to CPython to support JIT compilers. There
is no expectation, though, to ship a JIT compiler with CPython. This is because
CPython compiles with nothing more than a C89 compiler, which allows it to run
on many platforms. But adding a JIT compiler to CPython would immediately limit
it to only the platforms that the JIT supports.
### Does this help with using CPython w/ .NET or UWP?
No. Use [Python.NET](http://pythonnet.github.io) if you want integration with Python and .NET 4.
## Code of Conduct
This project has adopted the
[Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the
[Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
or contact [opencode@microsoft.com](mailto:opencode@microsoft.com)
with any additional questions or comments.
# Release notes
## 2.0.0
* Updated to .NET 7
## 1.2.7
* Fix a bug in the native x86_64 disassembler giving an error about compatibility on Windows Intel CPUs
## 1.2.6
* Extend optimizations in `RelWithDebInfo` mode
## 1.2.5
* Changed the `pyjion.config(debug=)` setting to allow True or False (as before), or 0 (Release), 1 (Debug), 2 (ReleaseWithDebugInfo)
## 1.2.4
* Updated to rich 11.0
* Fix a bug in the CIL disassembler for constant double (LDC_R8) opcodes
## 1.2.3
* Unboxed operations won't update frame last instruction since they're unable to raise exceptions (making them faster)
## 1.2.2
* Added `pyjion.dis.flow_graph()` function to get a DOT control flow-graph of CIL basic blocks
* Added `pyjion.dis.cil_instructions()` function to get a list of CIL instructions from a compiled function
* Enable ASAN for Windows (compile-time option)
* CIL compiles to short branch opcodes when target is within 1 byte
* Show effective branch target on CIL disassembly output
## 1.2.1
* Fixes a bug in OPT-12 (method caching) where it would store the incorrect cache address for a global type of subclass. Bug seen in SQLalchemy.
## 1.2.0
* PGC unboxing errors are avoided when functions are called with different argument types to those it was optimized with.
* PGC types will now be inferred across jump statements, for loops and other small scopes, improving performance
* LOAD_METHOD will use cached pointers for builtin types like `dict`, `list`, etc. meaning LOAD_METHOD is faster in many cases
* Dictionary merge operators, `|` and `|=` will assert the return type as dict
* Fixes a crash on Windows when referencing call points or sequence points for a free'd module
* Fixes an issue running `pyjion -m module` with arguments
## 1.1.1
* Fixed a critical bug where recursive functions that use a mutable container type (e.g. list) causes a decref to the wrong object and subsequent crash.
* Fixes a bug on graph generation for recursive functions causing a crash in some situations
* Fixes a bug on method calls, which called the wrong method when the class was copied using `copy.copy()`
* Reduced memory consumption for method calls
## 1.1.0
* Added unboxed integer operations for BINARY_LSHIFT, BINARY_RSHIFT, BINARY_AND, BINARY_OR, BINARY_XOR
* BINARY_MULTIPLY and BINARY_POWER will stay unboxed if the right-hand operator is a constant that won't overflow (e.g. x ** 2)
* Added unboxed UNARY_NOT,UNARY_POSITIVE and UNARY_NEGATIVE operation for float, bool and int types
* Added unboxed UNARY_INVERT for int and bool types
* Added unboxed STORE_SUBSCR for bytearrays
* The types of global variables are profiled at compile-time
* Improved performance of bytearrays, by adding an unboxed bytearray type and unboxed slice operations for bytearrays, yielding unboxed integers
* Fixed a reference count bug with unboxed range iterators
* PGC will now allow an int of value 0 or 1 to be unboxed into a bool
* Unboxing of integers is now more efficient and allows for True to be unboxed into 1 and False into 0
## 1.0.0
* Fix a bug on `pyjion.config()` crashing when called with invalid arguments (#401)
* Update to .NET 6 GA
* LOAD_GLOBAL is faster when neither globals or builtins have changed since compiling, by caching the object address.
* Calls to Python functions are now routed through Vector Call (faster)
* Improved performance of calling builtin types, like int(), str(), etc.
* Calls to C Functions are faster
* Added an OptimisticIntegers optimization to level 2 to inspect integer values and unbox them if they're small
* Abstract value profiler will assert tuples of constant values (e.g. float, int) based on value
* LOAD_ATTR will infer the attribute type of classes using a cached attribute lookup table when optimization `AttrTypeTable` (level 1) is enabled
* Fix a bug that would reset the optimization level to 1 whenever `pyjion.enable()` was called
* Fix a bug that would cause an invalid jump operation and a failed compilation for EXTENDED_ARG jumps which occur in big functions
## 1.0.0 (rc4)
* Added ARM64 for Apple macOS (M1 Silicon). The JIT will emit native ARM64 assembly. Disassembler not supported.
* Added Linux/ARM64 support and a manylinux wheel
* Added Windows/ARM64 support
* All JIT configuration is now set using the `pyjion.config()` function instead of `enable_feature()`/`disable_feature()`
* Fixed a bug where `pyjion.graph()` would cause an exception if graphing was not enabled when the function was compiled
* Added support for the `SETUP_ANNOTATIONS` opcode
* Added support for generators in 3.10
* Fixed a bug in the DUP_TOP_TWO opcode with escaped variables
* UNPACK_SEQUENCE will emit types for constant tuples of string, int and float
* STORE_FAST is now profiled during the probe stage of PGC, leading to drastically improved performance in many cases where unboxed ints and floats can be used
* Added a simple benchmark suite script (`Tests/benchmarks/suite.py`)
* Upgraded scikit-build to 0.12 for native VS2019 support
## 1.0.0 (rc3)
* Updated to .NET 6 RC1
* Added Python 3.10 support
* Experimental `try..except` statements, stacked exception handlers and exception filtering. Disabled by default
* Fixed a bug on LOAD_METHOD not raising an exception immediately if the method could not be resolved
* Remove `enable_tracing()` and `enable_profiling` functions in 3.10 builds. Profiling and tracing is detected on compilation and available via the `.info()` method
* Added support for PEP626 (fast line tracing)
* Extended profiling support for CFunction calls
* PyTrace_RETURN now correctly sends the return value as an argument as per CPython spec
* Fixed a bug causing SEG when range iterators are escaped
## 1.0.0 (rc2)
* BINARY_MULTIPLY and BINARY_POWER will assume the resulting integer is a big integer (not unboxed)
* Introduced two optimizations IntegerUnboxingMultiply and IntegerUnboxingPower which are applied at optimization level 2. Try level two if you work with integers, but at smaller values to see better performance.
* Pyjion will infer that `range(n)` generates integers in iterator to improve unboxing
* LOAD_BUILD_CLASS will infer a function type instead of Any (#42)
* Instruction graphs will include the name of fast locals
* Instruction graph const values are capped to 40 characters
* Added abstract types for all builtins (#339)
* `pyjion.info()` will now return a JitInfo object
* Optimization flags that were applied to a function during compilation are available in `JitInfo.optimizations`
* All optimizations are now runtime flags instead of compile-time features
* Unboxing PGC errors will raise `pyjion.PyjionUnboxingError` (ValueError) instead of ValueError
* Instruction graphs will show conditional branches (in orange)
* Fixed a bug in generators where mixed unboxed/boxed fast locals would yield the wrong values with PGC between the first and second compilation stages
* Fixed a de-optimization that happened in rc1 due to PGC asserting the abstract kind on the profiling phase and then always asserting that integers were big-integers
* Fixed a bug where unboxed locals were decrefing frame locals on yield
* Generators will not unbox fast locals for stability reasons
* Fixed a regression on unboxed integers, caused by PGC values being set as Any
* Assert return types for float object methods (as_integer_ratio, conjugate, is_integer, hex)
## 1.0.0 (rc1)
* Added `pyjion` command-line script to complement the `python -m pyjion` command
* The pyjion CLI has flags for enabling profiling, tracing, optimization level, graphs and debugging
* Unboxing integers that don't fit into `long long` will raise a ValueError.
* Pyjion will mark any values above 1 billion as "big integers" and not escape them to reduce the chance of overflows.
* Floating point `__pow__` with negative values matches all behaviour of CPython
* Raising `0` to a negative power will raise a `ZeroDivisionError`
* PGC no longer uses a reference to probed values, dramatically reducing memory consumption between the first and second compile cycles
* Fixed a bug where `statistics.variance([0, 0, 1])` would raise an assertion error because of an overflow raised in Fraction arithmetic (#326)
* Fixed a bug on calling `sys.settrace(None)` would cause a segmentation fault (#330)
* Fixed a bug on optimized calls to custom types would crash on the 3rd execution because of the way PGC held and released references.
* Refactored Pyjion's test suite to Pytest
* Rewrote the documentation site
* Fixed a bug in the native disassembler printing empty comment lines
* Corrected the type signature of `pyjion.get_offsets()`
* Fixed a bug on changed methods for object (like a global) causing crashes because of the way load_method was optimized (#335)
## 1.0.0 (beta7)
* Added `pyjion.symbols(callable)` API to fetch the dictionary of external call tokens
* Extended the `dis()` and `dis_native()` methods with a flag to not print the program counter (`print_pc=False`)
* Improved the `dis_native()` method to print the name of the method call after the `call` instructions as a line comment
* Fixed a bug in `dis_native()` which showed unresolved sequence points at the top of the printout
* Fixed a bug where `in` (CONTAINS_OP) result wasn't being checked for exceptions and the next operation would segfault if the `in` operation returned an error result.
* The IL in `dis()` is closer in syntax to ILDasm and easier to read
* Added a `pyjion.status()` method to get runtime data on the JIT
* Windows will now observe the `DOTNET_ROOT` and `DOTNET_LIB_PATH` environment variables
## 1.0.0 (beta6)
* Updated to .NET 6 preview 6
* Fixed a bug where `ord()` builtin would return the wrong type (#315)
* `pyjion.dis.dis()` and `pyjion.dis.dis_native()` will show sequence points as comments
* The BINARY_POWER and INPLACE_POWER opcodes will always return a native python long instead of an escaped integer, to avoid overflows
## 1.0.0 (beta5)
* Fixed a bug on large dictionary literals (>100 keys)
* Improved the efficiency of the BUILD_TUPLE, BUILD_LIST, BUILD_CONST_KEY_MAP, and BUILD_SET opcodes
* Fixed a bug with comparison of numpy arrays being unboxed into a boolean instead of staying as an array (#310)
## 1.0.0 (beta4)
* Support for the `yield` keyword and Python generators
## 1.0.0 (beta3)
* Instruction graphs can be enabled with `pyjion.enable_graphs()` and then exported by `pyjion.get_graph(f)`
* Pyjion will raise an ImportError if .NET is missing instead of a system exit
## 1.0.0 (beta2)
* Fast locals can store unboxed values
* Method calls are optimized for known types by asserting the return type, e.g. `str.upper()` returns a string
* Updated to .NET 6 preview 5
* Pyjion can be run using `python -m pyjion <command>`, e.g. `python -m pyjion script.py` or `python -m pyjion -m unittest`
## 1.0.0 (beta1)
* Added unboxing for integers (OPT-16)
* Added unboxing for bool
* Fixed a bug with interned hash maps on Windows
## 1.0.0 (alpha4)
* Added unboxing and escape analysis for floating point objects (OPT-16)
* Removed OPT-8 as it is superseded by OPT-16
## 1.0.0 (alpha3)
* Updated to .NET 6 preview 4
## 1.0.0 (alpha2)
* Debuggable JIT methods can be toggled at runtime using `pyjion.enable_debug()`/`pyjion.disable_debug()`
* Added option for including Python bytecode disassembly in Pyjion disassemble printouts on `pyjion.dis.dis()` and `pyjion.dis.dis_native()`
* Added API `pyjion.get_offsets(callable)` to get the offsets of Python Opcode <> IL offset <> native offset.
* Moved internal representations to fixed width standard types.
## 1.0.0 (alpha1)
* Pyjion uses .NET 6 Preview 3 as the compiler, for Linux and macOS make sure you have installed it first
* Rich comparisons (==, <, >) of floating point numbers are significantly faster (OPT-17)
* All method calls are faster by enforcing vectorcall protocol and inlining anything below 10 arguments (OPT-16)
## 0.15.0
* PGC now observes and optimizes heap-allocated (user-defined) types
* Fixed a crash on certain recursive functions with PGC enabled
## 0.14.1
* Fixed macOS wheel name
## 0.14.0
* LOAD_ATTR is now optimized by for types that implement the tp_getattr by prehashing the names (OPT-15)
* JIT will emit a direct call to LOAD_ATTR tp_getattro/tp_getattr slots for builtin types
* macOS wheels are now compiled with Clang PGO
* PGC will only profile non heap-allocated types (ie not user specified types) as type objects could be deallocated between compilation cycles
* Reduced stack effect during frame calls/function calls
* Improved performance on function calls
* Py_MakePendingCalls will be called every 100 instructions (previously 10), configurable at compile-time through the `EMIT_PENDING_CALL_COUNTER` definition
* Updated to .NET 5.0.5 (5.0.202)
* Fixed a bug in PGC for large functions meaning they wouldn't be optimized
* Implemented PGC for BINARY_SUBSCR (OPT-5)
* Implemented PGC for STORE_SUBSCR (OPT-6)
* Implemented PGC for all inplace and regular binary operators (+, -, / etc) see OPT-13
## 0.13.0
* The compiler will now fail (and default back to CPython) if .NET emits a FAST_FAIL helper
* UNPACK_SEQUENCE is rewritten to be more efficient and use optimized paths for LIST and TUPLE types
* f-string (BUILD_STRING) is rewritten to be more efficient
* UNPACK_EX is rewritten to remove the requirement for dynamic heap allocation (and the stack canary) and leverage .NET compiler's dynamic eval stack
* PGC implemented for UNPACK_SEQUENCE
* PGC implemented for BINARY_SUBSCR
* PGC implemented for CALL_FUNCTION/OPT-14
## 0.12.0
* Added PGC emitter to first compile pass
* Drastically simplified the compilation process, resulting in a smaller call stack and allowing for more recursion (and better performance)
* Added a field to the pyjion.info() dictinary, `compile_result`, indicating cause of compilation failure (if failed), see `AbstractInterpreterResult` for enumerations
* Fixed a bug in pyjion.dump_native/pyjion.dis.dis_native disassembling the wrapper function
* Incompatible functions (those with async, yield keyword) are marked as incompatible early in the compilation process
* Fixed a bug in OPT-13 if the type changed under certain circumstances
* Arguments to a frame are now marked as volatile and requiring type guards for certain optimizations
* Any Python type passed as an argument is now available to be optimized by OPT-13, OPT-12
* Fixed a bug occuring on Linux and Windows in sre_parse._compile which caused a GuardStackException when doing an inline decref operation.
* Added an environment variable DOTNET_LIB_PATH to allow specifying the exact path to libclrjit
## 0.11.0
* Added OPT-13 (OPTIMIZE_TYPESLOT_LOOKUPS) to optimize the type slots for all binary operators and resolve the precedence at compile-time (only for known types)
* Added OPT-14 (OPTIMIZE_FUNCTION_CALLS) to optimize calls to builtin functions
* Optimize all frame locals by determining abstract types on compilation
* Bugfix: Fixed a crash on f-strings with lots (>255) arguments
* Bugfix: Will now skip all functions containing the use of `exec()` as it contains frame globals which are not supported
* Updated to .NET 5.0.3
* Updated the containers to Ubuntu 20
* Added fileobject abstract type
* Added enumerator abstract type
* Added code object abstract type
* Added integration tests for reference leaks for all binary operations (thanks @amaeckelberghe)
* Added module type (thanks @vacowboy75)
## 0.10.0
* Added OPT-12 (OPTIMIZE_BUILTIN_METHOD) to pre-lookup methods for builtin types and bypass LOAD_METHOD (PyObject_GetMethod)
* Optimized LOAD_METHOD to recycle lookups for the same object
* Expanded OPT-8, OPT-9, OPT-11, OPT-12 for nested stacks (e.g. inside expressions)
* Added a frozen set abstract type
## 0.9.0
* Added OPT-11 (OPTIMIZE_BINARY_SLICE) to optimize the BUILD_SLICE and BINARY_SUBSCR operations into a single function when the slice start, stop and step is None or a const number.
* Fixed a bug in the set_optimization_level() being reset (thanks @tetsuo-cpp)
* Added a bytearray abstract value kind (thanks @tetsuo-cpp)
* Added a type abstract value kind (thanks @tetsuo-cpp)
* Optimized the compiled instructions to only update the frame last instruction field on error/exit branch
* Removed the "periodic work" method which was called for every for/while loop and put a function to call Py_MakePendingCalls for every 10th loop
* Added an improvement to the process stage to infer the abstract types of return values to methods of builtin types, e.g. str.encode
* Added a check in dis_native for when the compiled function wasn't compiled (thanks @tetsuo-cpp)
* dis_native will now pretty print the assembly code when the `rich` package is installed (thanks @C4ptainCrunch)
* `pyjion[dis]` is a new package bundled with pystorm3 and rich (thanks @C4ptainCrunch)
## 0.8.0
* Enhanced the process stage of the compiler with new abstract types, iterable, bytearray, codeobject, frozenset, enumerator, file, type and module
* Process stage will assert the abstract return type of any call to a builtin function (e.g. list(), tuple()), which will kick in the optimizations for a broader set of scenarios
* Added OPT-8 (OPTIMIZE_BINARY_FUNCTIONS) to combine 2 sequential binary operations into a single operation. Adds about 15-20% performance gain on PyFloat operations.
* Added OPT-9 (OPTIMIZE_ITERATORS) to inline the FOR_ITER opcode of a listiter (List iterator) into native assembly instructions.
* Added OPT-10 (OPTIMIZE_HASHED_NAMES) to precompute the hashes for LOAD_NAME and LOAD_GLOBAL dictionary lookups
* Fixed a bug where looking up a known hash for a dictionary object (optimized BINARY_SUBSCR) wouldn't raise a KeyError. Seen in #157
## 0.7.0
* Fixed a bug in JUMP_IF_FALSE_OR_POP/JUMP_IF_TRUE_OR_POP opcodes emitting a stack growth, which would cause a stack underflow on subsequent branch checks. JIT will compile a broader range of functions now
* Implemented PEP590 vector calls for methods with 10+ arguments (thanks @tetsuo-cpp)
* Implemented PEP590 vector calls for functions with 10+ arguments
* Fixed a reference leak on method calls with large number of arguments
* Support for tracing of function calls with 10+ arguments
* Disabled OPT-4 as it is causing reference leaks
## 0.6.0
* Added OPT-6 optimization. Frame constants are now used to speed up assignments to lists and dictionaries. STORE_SUBSCR will assert if something is a list, or dict and shortcut
the assignment logic.
* Added OPT-7 optimization. The binary subscript operator is compiled to faster path under a set of circumstances, especially if the index/key is a frame constant. Hashes are precomputed
and indexes for integer constants are converted to native numbers at compile-time.
* The native machine-code disassembler will show the actual position of the JITed code in memory, instead of starting the offset at 0
* The `pyjion.dump_native()` function returns a tuple with bytes, length and position
* Type inferencing has been improved for all inplace and binary operations
* Windows builds from source are fixed for when the user wants to compile against a checkout of .NET
* Implemented FAST_DISPATCH for additional opcodes
* Added a test runner for the CPython regression suite that tests the JIT in isolation
* Fixed a reference leak of (self) for the LOAD_METHOD opcode
* Fixed a reference leak of non C functions being called via Call<N> (CALL_FUNCTION)
* Fixed a bug where (very) large tuples being created via the BUILD_TUPLE opcode would cause an overflow error
* Fixed a bug on BUILD_MAP being called with very large dictionaries caused a fatal error
## 0.5.0
* Added OPT-4 optimization. Frame locals (named variables known at compilation) using the LOAD_FAST, STORE_FAST and DELETE_FAST
opcodes will use native .NET locals instead of using the frame's f_localsplus array.
* Improved performance in LOAD_FAST and STORE_FAST through OPT-4
* Added OPT-5 optimization. Frame push/pop on entry/exit are now inline CIL instructions.
* LOAD_FAST skips unbound local checks when proceeded by a STORE_FAST (i.e. slot is definitely assigned)
## 0.4.0
* Fixed a crash bug where CPython checks recursion depth from ceval state, which may not be set
* Implemented a faster check for recursion depth
* Fixed a bug on LOAD_CLOSURE operator not being set
* Fixed OPT-2 on Windows and Linux
* Fixed a bug where the wrong CIL opcode was being used to subtract values, would throw an overflow error and fail back into EFD.
* Implemented the .NET EE exception handlers for guard stack canaries, overflow errors, and null reference exceptions
* Implemented a more efficient case of ld_i(1)
* Corrected cases of ob_refcnt to use 64-bit signed integers
* No longer print error messages on release code for unimplemented .NET EE methods
* Fixed a bug on the incorrect vtable relative field being set
* Fixed a bug where tracing and profiling would be emitted even when not explicitly enabled
* .NET Exceptions are transferred into Python exceptions at runtime
## 0.3.0
* Added an optimization (OPT-1/OPTIMIZE_IS) to inline the "is"/ "is not" statement into a simple pointer comparison with jump statement. Compiles to inline machine code instead of a method call
* Added an optimization (OPT-2/OPTIMIZE_DECREF) to decrement the refcount without a method call, when the object refcount is >1 and then call _Py_dealloc if the ref count becomes 0. Replaces the previous method call
* Windows now uses the system page size instead of the default value of 1MB
## 0.2.1
* Added support for .NET 5.0.1
* Implemented a CIL modulus emitter
## 0.2.0
* Added support for profiling compiled functions by enabling profiling (`pyjion.enable_profiling()`)
* Added support for profiling C function calls, returns and exceptions
* Implemented a faster call path for functions and methods for 5-10 arguments
* Fixed a bug where the page size defaulted to 0 in the .NET EE, which caused a failed assertion (and fails to compile the function), would fix a large % of functions that previously failed to compile
## 0.1.0
* Added support for debugging compiled functions and modules by enabling tracing (`pyjion.enable_tracing()`)
* Added support for debugging to catch unhandled/handled exceptions at runtime when tracing is enabled
* Added support for opcode-level tracing
* Fixed a bug on executing Pyjion with pydevd (VScode/PyCharm debugger) would cause the Python process to crash because of a doubly-freed code object (#7)
## 0.0.7
* Added a WSGI middleware function to enable Pyjion for Flask and Django (#67)
* Fix a bug on dictionary merging for mapping types incorrectly raising a type error (#66)
## 0.0.6
* Implemented supported for disassembling "large" methods into CIL (#27)
* Added type stubs for the pyjion C extension
* Fix a bug where merging or updating a subclassed dictionary would fail with a type error. (#28)
## 0.0.5
* Fixed a critical bug where method calls with large numbers of arguments, and the argument was a tuple could cause a segmentation fault on GC collection.
* Tested support for IPython REPL
* Fixed a bug where importing pyjion.dis after enabling the JIT would cause a stack overflow
* Has around 50% chance of working and not causing your computer to explode, or worse, segmentation fault
## 0.0.4
* Added a stack probe helper for Linux (will use JIT in more scenarios)
* Enabled support for running unit tests in Linux
* Fixed a bug where JIT would crash when a method call failed because of a bad-lookup
* Implemented helper method redirection for Linux to support PIC compiled symbols
* Has around 35% chance of working and not causing your computer to explode, or worse, segmentation fault
* Improved discovery of .NET libraries on Linux
* Fixed a bug where a garble-named log file would be generated (should be JIT timings log)
## 0.0.3
* Installable bdist_wheel for Ubuntu, Debian, macOS 10.15, 11 (10.16) and Windows x64
* Installable manylinux2014 wheel with clrjit.so bundled in
* Added multithreading/multiprocessing support
* Fixed a bug where the wheel would be broken if there are two distributions of Python 3.9 on the system
* Has around 30% chance of working and not causing your computer to explode, or worse, segmentation fault.
## 0.0.2
* Installable source distribution support for macOS, Windows and (barely) Linux.
## 0.0.1
* It compiles on my machine
%prep
%autosetup -n pyjion-2.0.0
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-pyjion -f filelist.lst
%dir %{python3_sitearch}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Fri May 05 2023 Python_Bot <Python_Bot@openeuler.org> - 2.0.0-1
- Package Spec generated
|