Hacker News new | ask | show | jobs
by dralley 1513 days ago
>pathlib and dataclasses. In a regular code they are great. On a bottleneck however, they are very slow.

Do you have any numbers to back this up? Why would Pathlib be slow?

1 comments

Anthony Sottile has a good bit on it: https://www.youtube.com/watch?v=tFrh9hKMS6Y

TL;DR: Path() initialization is very heavy compared to simple strings, and subsequent path operations produce new Path() objects every time.

The video then illustrates the point with a patch to the black formatter cache yielding a 40X speedup.

Oh, that is unfortunate. Thanks for the tip.