Commit f5bf391
authored
Optimize lstripChars, rstripChars, and stripChars via specialization (#236)
This PR optimizes `lstripChars` / `rstripChars` / `stripChars` built-in
functions by using the specialization framework from #119 /
0bd255a to pre-compile and re-use
`Pattern` instances when the replacement / strip arguments are
constants.
In Java, `String.replaceAll()` compiles and uses a `Pattern` under the
hood and this is relatively expensive; specialization lets us save this
cost when the `chars`-to-be-stripped are constant.
## Testing
**Correctness**: ran all tests with a manual change to disable static
function application optimizations (a prerequisite required to achieve
full test coverage, as the static application prevents specialization
from kicking in during most tests). In a followup, I think we should
explore adding flags for optimizer features and running all tests
with/without optimization.
**Performance**: ran benchmarks on a large file and with this change I
save ~11% of allocated bytes and ~8% of wall time. I ran that same file
through `RunProfiler` and saw a large speedup in `stripChars`, costing
~619ns/call before and ~154ns/call after.1 parent 15c9e0d commit f5bf391
1 file changed
Lines changed: 79 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
456 | 456 | | |
457 | 457 | | |
458 | 458 | | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
459 | 535 | | |
460 | 536 | | |
461 | 537 | | |
| |||
1025 | 1101 | | |
1026 | 1102 | | |
1027 | 1103 | | |
1028 | | - | |
1029 | | - | |
1030 | | - | |
1031 | | - | |
1032 | | - | |
1033 | | - | |
1034 | | - | |
1035 | | - | |
1036 | | - | |
1037 | | - | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
1038 | 1107 | | |
1039 | 1108 | | |
1040 | 1109 | | |
| |||
0 commit comments