Commit 4e67f09
committed
More optimization.
- Cache the result of os.path.split(root)[1].lower() (this is *very*
costly, relatively speaking).
- Cache some more string operations on the Prepared class, and use
`__slots__` to speed up attribute access.
It would be nice to also use `__slots__` on FastPath, but FastPath
relies on being able to overwrite the joinpath method at the instance
level and that's not compatible with `__slots__`; moving joinpath to
always be on the instance (`self.joinpath = Path(self.root).joinpath`)
is slower due to the sometimes unnecessary creation of a Path instance.
Overall the new version's runtime (on a previously described benchmark)
is around 60% of the original one (i.e. a bit less than 2x speedup).1 parent bc93d0f commit 4e67f09
1 file changed
+13
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
408 | 408 | | |
409 | 409 | | |
410 | 410 | | |
| 411 | + | |
411 | 412 | | |
412 | 413 | | |
413 | 414 | | |
| |||
430 | 431 | | |
431 | 432 | | |
432 | 433 | | |
433 | | - | |
434 | | - | |
| 434 | + | |
435 | 435 | | |
436 | | - | |
| 436 | + | |
437 | 437 | | |
438 | 438 | | |
439 | 439 | | |
| |||
452 | 452 | | |
453 | 453 | | |
454 | 454 | | |
455 | | - | |
456 | | - | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
457 | 458 | | |
458 | | - | |
459 | 459 | | |
460 | 460 | | |
461 | 461 | | |
462 | 462 | | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
463 | 466 | | |
464 | | - | |
465 | | - | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
466 | 470 | | |
467 | | - | |
| 471 | + | |
468 | 472 | | |
469 | 473 | | |
470 | 474 | | |
| |||
0 commit comments