Commit 4fe3aac
committed
This PR aims to replace the Formatter's standard `Vec` and `Box` usages with `ArenaVec` and `ArenaBox` to gain performance, which could reduce the `drop` overhead.
There are three key changes:
1. Change the Document's element from `Vec<FormatElement<'a>>`
```diff
pub struct Document<'a> {
- elements: Vec<FormatElement<'a>>,
+ elements: &'a [FormatElement<'a>],
}
```
2. Change the `FormatElement::interned`'s argument from `Rc<[FormatElement<'a>]>` to `&'a [FormatElement<'a>]`
```diff
- pub struct Interned<'a>(Rc<[FormatElement<'a>]>);
+ pub struct Interned<'a>(&'a [FormatElement<'a>]);
```
3. Change the `FormatElement::variants`'s variants from `Box<[Box<[FormatElement<'a>]>]>` to `&'a [&'a [FormatElement<'a>]]`
```diff
pub struct BestFittingElement<'a> {
- variants: Box<[Box<[FormatElement<'a>]>]>,
+ variants: &'a [&'a [FormatElement<'a>]],
}
```
All other changes stem from those mentioned above.
Replacing the `Rc` with `&a` reference approach was suggested and guided by @overlookmotel. Thank you!
1 parent 7d1ebad commit 4fe3aac
File tree
10 files changed
+105
-75
lines changed- crates/oxc_formatter/src
- formatter
- format_element
- ir_transform/sort_imports
- write
- jsx
10 files changed
+105
-75
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
175 | 177 | | |
176 | 178 | | |
177 | 179 | | |
178 | | - | |
| 180 | + | |
179 | 181 | | |
180 | 182 | | |
181 | 183 | | |
182 | 184 | | |
183 | | - | |
| 185 | + | |
184 | 186 | | |
185 | 187 | | |
186 | 188 | | |
187 | 189 | | |
188 | | - | |
| 190 | + | |
189 | 191 | | |
190 | 192 | | |
191 | 193 | | |
192 | 194 | | |
193 | 195 | | |
194 | 196 | | |
195 | | - | |
| 197 | + | |
| 198 | + | |
196 | 199 | | |
197 | 200 | | |
198 | 201 | | |
199 | | - | |
| 202 | + | |
200 | 203 | | |
201 | 204 | | |
202 | 205 | | |
203 | 206 | | |
204 | | - | |
205 | | - | |
| 207 | + | |
| 208 | + | |
206 | 209 | | |
207 | 210 | | |
208 | 211 | | |
| |||
493 | 496 | | |
494 | 497 | | |
495 | 498 | | |
496 | | - | |
497 | | - | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
498 | 506 | | |
499 | 507 | | |
500 | 508 | | |
| |||
509 | 517 | | |
510 | 518 | | |
511 | 519 | | |
512 | | - | |
| 520 | + | |
513 | 521 | | |
514 | 522 | | |
| 523 | + | |
515 | 524 | | |
516 | | - | |
| 525 | + | |
517 | 526 | | |
518 | 527 | | |
519 | 528 | | |
| |||
522 | 531 | | |
523 | 532 | | |
524 | 533 | | |
525 | | - | |
526 | | - | |
| 534 | + | |
| 535 | + | |
527 | 536 | | |
528 | 537 | | |
529 | 538 | | |
530 | | - | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
531 | 545 | | |
532 | 546 | | |
533 | 547 | | |
534 | 548 | | |
535 | | - | |
536 | | - | |
| 549 | + | |
| 550 | + | |
537 | 551 | | |
538 | 552 | | |
539 | 553 | | |
| |||
567 | 581 | | |
568 | 582 | | |
569 | 583 | | |
570 | | - | |
| 584 | + | |
571 | 585 | | |
572 | 586 | | |
| 587 | + | |
573 | 588 | | |
574 | 589 | | |
575 | 590 | | |
| |||
588 | 603 | | |
589 | 604 | | |
590 | 605 | | |
591 | | - | |
| 606 | + | |
592 | 607 | | |
593 | 608 | | |
594 | 609 | | |
595 | 610 | | |
596 | 611 | | |
597 | 612 | | |
598 | | - | |
599 | | - | |
| 613 | + | |
600 | 614 | | |
601 | 615 | | |
602 | 616 | | |
| |||
614 | 628 | | |
615 | 629 | | |
616 | 630 | | |
617 | | - | |
| 631 | + | |
618 | 632 | | |
619 | 633 | | |
620 | 634 | | |
621 | 635 | | |
622 | 636 | | |
623 | 637 | | |
624 | | - | |
| 638 | + | |
625 | 639 | | |
626 | 640 | | |
627 | 641 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
2549 | 2550 | | |
2550 | 2551 | | |
2551 | 2552 | | |
2552 | | - | |
| 2553 | + | |
2553 | 2554 | | |
2554 | 2555 | | |
| 2556 | + | |
| 2557 | + | |
| 2558 | + | |
2555 | 2559 | | |
2556 | 2560 | | |
2557 | 2561 | | |
| |||
Lines changed: 8 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | | - | |
144 | | - | |
145 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | | - | |
| 153 | + | |
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | | - | |
162 | | - | |
| 161 | + | |
| 162 | + | |
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
| |||
Lines changed: 16 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| 13 | + | |
| 14 | + | |
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
| |||
146 | 149 | | |
147 | 150 | | |
148 | 151 | | |
149 | | - | |
| 152 | + | |
150 | 153 | | |
151 | 154 | | |
152 | | - | |
153 | | - | |
| 155 | + | |
| 156 | + | |
154 | 157 | | |
155 | 158 | | |
156 | 159 | | |
157 | 160 | | |
158 | 161 | | |
159 | | - | |
| 162 | + | |
160 | 163 | | |
161 | 164 | | |
162 | 165 | | |
163 | 166 | | |
164 | 167 | | |
165 | 168 | | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
| 169 | + | |
| 170 | + | |
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
| 184 | + | |
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
| |||
305 | 305 | | |
306 | 306 | | |
307 | 307 | | |
308 | | - | |
| 308 | + | |
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
321 | | - | |
| 321 | + | |
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
327 | | - | |
| 327 | + | |
328 | 328 | | |
329 | 329 | | |
330 | 330 | | |
| |||
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
337 | | - | |
338 | | - | |
| 337 | + | |
| 338 | + | |
339 | 339 | | |
340 | 340 | | |
341 | 341 | | |
| |||
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
351 | | - | |
| 351 | + | |
352 | 352 | | |
353 | 353 | | |
354 | 354 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
247 | | - | |
| 247 | + | |
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
5 | 9 | | |
6 | 10 | | |
7 | 11 | | |
| |||
26 | 30 | | |
27 | 31 | | |
28 | 32 | | |
29 | | - | |
| 33 | + | |
30 | 34 | | |
31 | 35 | | |
32 | 36 | | |
| |||
136 | 140 | | |
137 | 141 | | |
138 | 142 | | |
139 | | - | |
| 143 | + | |
140 | 144 | | |
141 | 145 | | |
142 | 146 | | |
| |||
0 commit comments