This is an archive of the discontinued Mercurial Phabricator instance.

rust: Preallocate the returned `Vec` in `utils::files::relativize_path`
ClosedPublic

Authored by SimonSapin on Mar 13 2021, 3:01 AM.

Details

Summary

Profiling rhg files > /dev/null on an old snapshot of mozilla-central
(with perf and the Firefox Profiler:
https://github.com/firefox-devtools/profiler/blob/main/docs-user/guide-perf-profiling.md)
showed non-trivial time spend in this function and in realloc.

This change makes the wall-clock time for that process on my machine
go from ~190 ms to ~150 ms.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

SimonSapin created this revision.Mar 13 2021, 3:01 AM
SimonSapin edited the summary of this revision. (Show Details)Mar 13 2021, 3:08 AM
Alphare accepted this revision.Mar 15 2021, 7:28 AM
Alphare added a subscriber: Alphare.

This will potentially cost a little bit more memory, but it's absolutely worth it for the speed gains.

I haven’t measured memory at all but I’d expect the effect to be very small or not noticeable since this function is typically called for printing the return value to stdout then deallocating it immediately. We’re not accumulating many "relativized" paths in memory at any given time.

pulkit accepted this revision.Mar 17 2021, 9:50 AM
This revision is now accepted and ready to land.Mar 17 2021, 9:50 AM