Commit f01a14a
authored
Fix bugs and performance issues in rewrite-python (#6851)
* Fix bugs and performance issues in rewrite-python
- Fix shared class-level mutable dict in InMemoryExecutionContext that
caused state leakage between instances
- Fix swapped last_access_time/last_modified_time args in
FileAttributes.from_path
- Fix error message in Cursor.first_enclosing_or_throw using wrong
variable (T.__name__ instead of type.__name__)
- Use identity check (is not) instead of equality (!=) in all 63
PaddingHelper.padding properties to avoid O(n) __eq__ comparisons
- Use deque.popleft() instead of list.pop(0) in RpcReceiveQueue for
O(1) message consumption
- Combine multiple replace() calls into single operations in
visit_right_padded and parse_python_source
- Remove unused imports and dead code
* Extract shared utilities and buffer RPC stdin reads in rewrite-python
- Extract duplicated import helpers (get_qualid_name, get_name_string,
get_alias_name, pad_right) into import_utils.py, replacing copies in
add_import.py, remove_import.py, and change_import.py
- Extract duplicated format helpers (common_margin, concatenate_prefix)
into format/_helpers.py, replacing copies in minimum_viable_spacing.py
and normalize_format.py
- Replace byte-at-a-time os.read(fd, 1) in RPC server with a buffered
_StdinBuffer that reads in 8 KB chunks, reducing syscalls per message
from ~25+ to 1-21 parent dd5dcb9 commit f01a14a
18 files changed
Lines changed: 320 additions & 391 deletions
File tree
- rewrite-python/rewrite/src/rewrite
- java
- python
- format
- recipes
- rpc
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | 28 | | |
32 | 29 | | |
33 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
569 | 569 | | |
570 | 570 | | |
571 | 571 | | |
572 | | - | |
| 572 | + | |
573 | 573 | | |
574 | 574 | | |
575 | 575 | | |
| |||
0 commit comments