How often does real code call abspath on the current working directory? I'm somewhat sceptical that making the code more complicated here is worth it for such an edge case
Reacted by Barney Gale, Kerim Kabirov and Erlend E. Aasland
This special case makes posixpath.relpath() with a single argument 4-6% faster.
Hmm. In my opinion, this particular optimisation is not worth it for a speedup of that magnitude. The refactor makes the code of this function look quite odd (the kind of thing that somebody keen on "refactoring" or "simplifying" the code of os.path might propose rewriting in a PR), and it's quite unobvious to a reader of the code that it's been deliberately written that way in order to speedup relpath().
Activity
AlexWaygood commented on Apr 8, 2024
How often does real code call abspath on the current working directory? I'm somewhat sceptical that making the code more complicated here is worth it for such an edge case
nineteendo commented on Apr 8, 2024
This speeds up posixpath.relpath() with 1 argument at no cost.
AlexWaygood commented on Apr 8, 2024
I see. That would be useful information to edit into the issue description.
erlend-aasland commented on Apr 9, 2024
How much is that speedup? According to your PR there is no speedup for the general call with one argument.
nineteendo commented on Apr 9, 2024
I'll do a benchmark soon. The pull request currently doesn't compare the performance of posixpath.relpath(), but it will be at most 13% faster.
nineteendo commented on Apr 9, 2024
This special case makes posixpath.relpath() with a single argument 4-6% faster.
AlexWaygood commented on Apr 9, 2024
Hmm. In my opinion, this particular optimisation is not worth it for a speedup of that magnitude. The refactor makes the code of this function look quite odd (the kind of thing that somebody keen on "refactoring" or "simplifying" the code of os.path might propose rewriting in a PR), and it's quite unobvious to a reader of the code that it's been deliberately written that way in order to speedup relpath().
nineteendo commented on Apr 9, 2024
OK, I was planning for a larger speedup anyway, that would apply to all relative paths: #117587.