Commit 670c03d
committed
Optimize parsing
A few changes:
1. Switch from `multiprocessing` to `concurrent.futures` with `ProcessPoolExecutor`. This is just to make the code easier to work with.
2. Perform `check_file()` as results return to the main process, in order to reduce peak memory usage. Previously all parsed files were kept in memory before being checked, leading to massive memory usage.
3. Construct parsers once per process, rather than once per file. Previously parser construction took ~5% of the runtime, this reduces it to a constant amount.
Benchmarked on a project with 238 templates.
Before:
```
$ time curlylint templates/**/*.html
All done! ✨ 🍰 ✨
curlylint templates/**/*.html 352.25s user 3.37s system 999% cpu 35.575 total
```
After:
```
$ time curlylint templates/**/*.html
All done! ✨ 🍰 ✨
curlylint templates/**/*.html 324.22s user 2.79s system 995% cpu 32.858 total
```
~8% of the time saved.
The parser remains quite slow, I think it does an unfortunate amount of backtracking.1 parent b64ec22 commit 670c03d
2 files changed
+33
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
7 | 11 | | |
8 | 12 | | |
9 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | | - | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
12 | 23 | | |
13 | 24 | | |
14 | 25 | | |
15 | 26 | | |
16 | 27 | | |
17 | 28 | | |
18 | | - | |
| 29 | + | |
19 | 30 | | |
20 | 31 | | |
21 | 32 | | |
22 | | - | |
23 | | - | |
24 | 33 | | |
25 | 34 | | |
26 | 35 | | |
27 | | - | |
28 | | - | |
| 36 | + | |
29 | 37 | | |
30 | | - | |
31 | | - | |
32 | 38 | | |
| 39 | + | |
33 | 40 | | |
34 | 41 | | |
35 | 42 | | |
36 | 43 | | |
37 | 44 | | |
38 | | - | |
| 45 | + | |
39 | 46 | | |
40 | 47 | | |
41 | 48 | | |
| |||
46 | 53 | | |
47 | 54 | | |
48 | 55 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | 56 | | |
| 57 | + | |
66 | 58 | | |
67 | 59 | | |
68 | | - | |
69 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
70 | 69 | | |
71 | 70 | | |
72 | 71 | | |
73 | 72 | | |
74 | 73 | | |
| 74 | + | |
| 75 | + | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
78 | | - | |
| 79 | + | |
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
| |||
0 commit comments