New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add faster TocTree._toctree_copy
method
#10988
Conversation
This was pair-programmed with @ax-lothas As in the standalone html builder the navigation is flattened out for every single html page, the code needs to create a specialized toctree for every html page. Previously this was done by deep-copying the complete navigation toctree and then stripping out the parts not needed on the particular page. With this change the code only (deep)-copies the needed parts of the toctree avoiding unnecessary copying+throwing-away The performance improvements seems to be smaller for smaller page counts and get bigger the more pages are involved: +----------------------------------+-----------+-----------+-------------------+ | 830 Source Files | 5.3.0 | 5.3.0mod | Ratio | +----------------------------------+-----------+-----------+-------------------+ | SingleThreaded | 49.137 s | 43.517 s | 0.885625903087287 | | Parallel (auto, 16 logical CPUs) | 13.334 s | 12.849 s | 0.963626818659067 | +----------------------------------+-----------+-----------+-------------------+ +----------------------------------+-----------+-----------+-------------------+ | 6166 Source Files | 5.3.0 | 5.3.0mod | Ratio | +----------------------------------+-----------+-----------+-------------------+ | SingleThreaded | 907.497 s | 521.945 s | 0.575147906825036 | | Parallel (auto, 16 logical CPUs) | 195.400 s | 150.139 s | 0.768367451381781 | +----------------------------------+-----------+-----------+-------------------+
def _toctree_copy(self, node: ET, depth: int, maxdepth: int, collapse: bool = False) -> ET: | ||
"""Utility: deep-copy a TOC but omit things with the semantics of ._toctree_prune. | ||
|
||
!!! MUST be kept consistent with ._toctree_prune !!! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by 'consistent' here?
A
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While _toctree_prune
deletes unneeded stuff from a (previously done) deep copy of the toctree, _toctree_copy
does the deep copy itself but only copies the parts, that _toctree_prune
would not delete. So assuming, that _toctree_prune
would be adjusted in order to e.g. not delete a particular node type, then _toctree_copy
would also need to be adjusted to copy that particular node type.
TBH we didn't fully understand the different node types involved here. It would probably be best, to completely get rid of _toctree_prune
in order not to have this consistency problem any more (maybe it is not that big of a problem if there aren't any adjustments to that code done in the foreseeable future). We tried getting rid of _toctree_prune
but found that it is used in another place and didn't feel confident enough to do the necessary changes.
# Conflicts: # sphinx/environment/adapters/toctree.py
TocTree._toctree_copy
method
Thanks! A |
This was pair-programmed with @ax-lothas
As in the standalone html builder the navigation is flattened out for every single html page, the code needs to create a specialized toctree for every html page.
Previously this was done by deep-copying the complete navigation toctree and then stripping out the parts not needed on the particular page.
With this change the code only (deep)-copies the needed parts of the toctree avoiding unnecessary copying+throwing-away
The performance improvements seems to be smaller for smaller page counts and get bigger the more pages are involved:
Relates