Commit 5faced6
committed
Fix str.translate SIMD performance for small strings
Address performance regressions in the SIMD optimization:
1. Add 1KB minimum size threshold - SIMD setup cost exceeds benefit
for smaller strings, causing 15-25% regression on <128 byte inputs
2. Use sample-based checking instead of full scan - check every 64th
byte plus last byte, avoiding O(n) overhead that caused 42% regression
in deletion cases
3. Single check at 256-byte mark - reduces repeated condition checking
overhead
4. Increase minimum remaining bytes from 32 to 512 - ensures enough
data to amortize SIMD setup cost
The SIMD fast path now only activates when:
- String length >= 1024 bytes
- No deletions detected
- At 256-byte offset with >= 512 bytes remaining
- Sample check passes (table populated for input charset)
https://claude.ai/code/session_0142fPYhFLFes4W9Tp6C3BhU1 parent 76e70d8 commit 5faced6
1 file changed
Lines changed: 30 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9449 | 9449 | | |
9450 | 9450 | | |
9451 | 9451 | | |
9452 | | - | |
9453 | | - | |
9454 | | - | |
9455 | | - | |
9456 | | - | |
| 9452 | + | |
| 9453 | + | |
9457 | 9454 | | |
9458 | | - | |
| 9455 | + | |
| 9456 | + | |
| 9457 | + | |
| 9458 | + | |
| 9459 | + | |
| 9460 | + | |
| 9461 | + | |
9459 | 9462 | | |
9460 | 9463 | | |
9461 | | - | |
9462 | | - | |
9463 | | - | |
9464 | | - | |
| 9464 | + | |
| 9465 | + | |
| 9466 | + | |
| 9467 | + | |
9465 | 9468 | | |
9466 | | - | |
9467 | | - | |
9468 | | - | |
9469 | | - | |
9470 | | - | |
9471 | | - | |
| 9469 | + | |
| 9470 | + | |
| 9471 | + | |
| 9472 | + | |
| 9473 | + | |
| 9474 | + | |
| 9475 | + | |
| 9476 | + | |
| 9477 | + | |
| 9478 | + | |
| 9479 | + | |
9472 | 9480 | | |
9473 | | - | |
| 9481 | + | |
| 9482 | + | |
| 9483 | + | |
| 9484 | + | |
9474 | 9485 | | |
9475 | 9486 | | |
9476 | | - | |
9477 | | - | |
9478 | | - | |
9479 | | - | |
| 9487 | + | |
| 9488 | + | |
9480 | 9489 | | |
9481 | 9490 | | |
9482 | 9491 | | |
| |||
0 commit comments