You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Special case for "" & "." in posixpath.abspath() #117639
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 commentedon Apr 8, 2024
How often does real code call
abspathon the current working directory? I'm somewhat sceptical that making the code more complicated here is worth it for such an edge casenineteendo commentedon Apr 8, 2024
This speeds up
posixpath.relpath()with 1 argument at no cost.AlexWaygood commentedon Apr 8, 2024
I see. That would be useful information to edit into the issue description.
[-]Special case for current dir in `posixpath.abspath()`[/-][+]Special case for "" & "." in `posixpath.abspath()`[/+]erlend-aasland commentedon Apr 9, 2024
How much is that speedup? According to your PR there is no speedup for the general call with one argument.
nineteendo commentedon 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 commentedon Apr 9, 2024
This special case makes
posixpath.relpath()with a single argument 4-6% faster.AlexWaygood commentedon 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.pathmight 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 speeduprelpath().nineteendo commentedon Apr 9, 2024
OK, I was planning for a larger speedup anyway, that would apply to all relative paths: #117587.