Commit 7302f17
committed
perf: Stop patching AST, use functions instead
Previously we were patching AST classes,
adding our own class to their base classes.
This allowed us to extend these classes,
by adding properties such as `kind`, `children`, etc.
Now we stop patching classes,
and re-define these properties
as simple functions that take
an AST node as argument.
Their result isn't cached anymore,
and we refactor them as iterators/generators.
We also stop using classes for AST nodes
unparsing into values / expressions when feasible.
Finally, we explode the node utilities
into different submodules, in the new `nodes` folder.
The result is:
- increased performance: for some reason, benchmarks
show that performance is better without cached properties.
Maybe MRO and cached values access was more costly.
- increased memory efficiency: without so many cached properties,
we consume a less memory. This is not super impactful
because `compile` and file reads represent almost
all our memory consumption.
- better static typing: the AST patch would have required
a mypy plugin to be understood correctly by mypy.
We don't need that anymore.
- easier-to-use library: we don't have to hardcode the call
to `patch_ast` anywhere anymore, and users won't have to either.1 parent bc446e4 commit 7302f17
17 files changed
Lines changed: 1813 additions & 1447 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
55 | | - | |
56 | 54 | | |
57 | 55 | | |
58 | 56 | | |
| |||
99 | 97 | | |
100 | 98 | | |
101 | 99 | | |
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 | 100 | | |
155 | 101 | | |
156 | 102 | | |
| |||
254 | 200 | | |
255 | 201 | | |
256 | 202 | | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
| 203 | + | |
| 204 | + | |
264 | 205 | | |
265 | 206 | | |
266 | 207 | | |
| |||
0 commit comments