perf!: use Cow to avoid OsString allocations#487
Conversation
|
About the |
|
And another thing: There is #390 which moves away from platform-dependent |
|
About the |
|
And another thing: There is #390 which moves away from platform-dependent |
This PR eliminates many temporary allocations from unnecessary uses of
OsString(they remain necessary forTreeIteratorwithout lending iterators).Previously, filename unescaping accounted for 43% of all total allocations, even in cases where there was nothing to unescape. This is avoided by checking for the presence of
\before, and using the original name if none was found.comp_to_osstrwas only responsible for 0.1% of allocations.Results
The following measurements are not from a proper benchmarking setup, but merely repeated low-delta backups with heaptrack (without LTO and with raised codegen-units, on a laptop):
Total allocations reduced from 173M to 98M in my case.
These changes did not lower peak RSS significantly (4.7GiB to 4.6GiB, probably noise or slightly reduced fragmentation), which is expected for mostly temporary allocations.
Using the global allocator with glibc 2.40, there wasn't much (if any) walltime improvement (284s to 274s, measured without heaptrack), but it might be more significant on platforms with weaker allocators like musl.