Skip to content

Commit e4dd77a

Browse files
committed
feat: compile with mypyc optionally
1 parent caba69c commit e4dd77a

File tree

4 files changed

+65
-4
lines changed

4 files changed

+65
-4
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"commit_hash": "f772d735cf3d71636cd19b2855238689c67e1363", "env_name": "virtualenv-py3.12", "date": 1716994131000, "params": {"arch": "arm64", "cpu": "Apple M1", "machine": "Noortheens-MacBook-Air.local", "num_cpu": "8", "os": "Darwin 21.2.0", "ram": "8589934592", "python": "3.12"}, "python": "3.12", "requirements": {}, "env_vars": {}, "result_columns": ["result", "params", "version", "started_at", "duration", "stats_ci_99_a", "stats_ci_99_b", "stats_q_25", "stats_q_75", "stats_number", "stats_repeat", "samples", "profile"], "results": {"benchmarks.TimeSuite.time_parser_init": [[0.0009463538881391287], [], "f2c6ff395f3b5b2fa63f6bae6bfdc8bf1c5a82b6cfc1c4f86aea11182d6dc0ea", 1716994621799, 1.1429, [0.00064567], [0.0019985], [0.00064893], [0.0012532], [1], [10]], "benchmarks.MemSuite.mem_parser_init": [[0], [], "d1d13e9271ac2f54e4467d6fa696e8594e58c73a636054c7408b1f70d6993831", 1716994621574, 0.11643], "benchmarks.PeakMemSuite.peakmem_parser_init_": [[25837568], [], "47681fd0575e44856252c83a7fa6e6fe4fe73a76dd56202580ae9b2fedc0259d", 1716994621690, 0.1085]}, "durations": {}, "version": 2}

Taskfile.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ tasks:
1212

1313
profile:
1414
cmds:
15-
- python tasks/profile_mem.py tee "logs/xonsh-parser-$(date "+%Y%m%d-%H%M%S").log"
15+
- mkdir -p .local/logs
16+
- python tasks/profile_mem.py | tee ".local/logs/xonsh-parser-$(date "+%Y%m%d-%H%M%S").$(git rev-parse --short HEAD).log"
1617

1718
ply-add:
1819
cmds:
@@ -38,7 +39,8 @@ tasks:
3839

3940
bench:
4041
cmds:
41-
- asv run --python=same --show-stderr
42+
- mkdir -p .local/logs
43+
- asv run --python=same --show-stderr | tee .local/logs/bench.$(date "+%Y%m%d-%H%M%S").$(git rev-parse --short HEAD).txt
4244

4345
bench-view:
4446
cmds:
@@ -52,4 +54,15 @@ tasks:
5254

5355
mypy:
5456
cmds:
55-
- watchexec -e py --clear -- mypy peg_parser
57+
- watchexec -e py --clear -- mypy peg_parser
58+
59+
mypyc:
60+
cmds:
61+
- env COMPILE_WITH_MYPYC=1 pip install -e .
62+
sources:
63+
- peg_parser/subheader.py
64+
- peg_parser/toke*.py
65+
66+
clean:
67+
cmds:
68+
- find peg_parser -name "*.so" -delete -print

experiments.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,33 @@ current=2625.3KiB, peak=9884.7KiB
113113
...
114114
Total allocated size: 9799.6 KiB
115115
```
116+
117+
# Compiling with mypyc doesn't improve much
118+
119+
needed to add following to use it successfully
120+
```py
121+
from mypy_extensions import mypyc_attr
122+
123+
124+
@mypyc_attr(allow_interpreted_subclasses=True)
125+
class Parser():
126+
...
127+
```
128+
129+
with mypyc
130+
```
131+
current=2125.4KiB, peak=28725.6KiB
132+
...
133+
1836 other: 757.9 KiB
134+
Total allocated size: 1387.7 KiB
135+
Took: 4.03s
136+
```
137+
138+
without mypyc
139+
```
140+
current=1904.7KiB, peak=1947.3KiB
141+
...
142+
1948 other: 596.0 KiB
143+
Total allocated size: 1901.8 KiB
144+
Took: 1.39s
145+
```

setup.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,21 @@ class CustomBuild(build):
2929
sub_commands = [("build_custom", None), *build.sub_commands] # noqa: RUF012
3030

3131

32-
setup(cmdclass={"build": CustomBuild, "build_custom": CustomCommand})
32+
options = {}
33+
34+
35+
if os.environ.get("COMPILE_WITH_MYPYC"):
36+
from mypyc.build import mypycify
37+
38+
options["ext_modules"] = mypycify(
39+
[
40+
"peg_parser/tokenize.py",
41+
"peg_parser/tokenizer.py",
42+
"peg_parser/subheader.py",
43+
]
44+
)
45+
46+
setup(
47+
cmdclass={"build": CustomBuild, "build_custom": CustomCommand},
48+
**options,
49+
)

0 commit comments

Comments
 (0)