Property path_name can be made more efficient
lverweijen opened this issue · comments
Laurent Verweijen commented
See
Line 119 in a507fa7
The property path_name
references sep
, but the property sep
is itself recursive, so it takes k^2
lookups but only k
lookups are needed. Furthermore, it does string addition in a (recursive) loop, but there are better ways to construct strings.
Perhaps change this to:
self.sep.join(reversed(self.ancestors))
or probably even faster:
ancestors = list(self.ancestors)
sep = ancestors[-1]._sep # No recursion because sep is taken directly from root
return sep.join(reversed(ancestors)
Kay Jan W. commented
Thanks for this suggestion! This will be implemented in v0.9.5 😄
Kay Jan W. commented
v0.9.5 is now live, do upgrade bigtree with pip install --upgrade bigtree
to get the latest changes.