Skip to content
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

twisted.web._flatten._getSlotValue copies slotData on every call. #11834

Closed
dreid opened this issue Mar 28, 2023 · 0 comments · Fixed by #11833
Closed

twisted.web._flatten._getSlotValue copies slotData on every call. #11834

dreid opened this issue Mar 28, 2023 · 0 comments · Fixed by #11833
Labels

Comments

@dreid
Copy link
Contributor

dreid commented Mar 28, 2023

Describe the incorrect behavior you saw

_getSlotValue attempts retrieve a value for a named slot from the slotData stack by using slice syntax to reverse it and then iterate over it.

This also causes it create a copy of the list.

In templates with large amounts of data such those used by pydoctor's summary pages. This copying ends up being a significant amount of time spent generating summary templates.

Describe how to cause this behavior

I discovered this issue while running pydoctor under the austin profiler.

I can reproduce it on twisted's own apidocs.

You can view the results of this profiling in speedscope: https://www.speedscope.app/#profileURL=https%3A%2F%2Fgist.githubusercontent.com%2Fdreid%2F197566471f39a96523f5065d19d0bf7f%2Fraw%2F3e7ec92a17bc82d40acceb1e2efcaa3ef7c8ef07%2Ftwisted-austin-trunk.speedscope

In the above profile _getSlotValue accounts for ~55s of the total runtime which was 509.42.

Describe the correct behavior you'd like to see
slotData should not need to be copied on every call to _getSlotValue simply to iterate over it in reverse.

Initial profiling using reversed instead resulted in reduced runtime to 357.36s

speedscope profile of using reversed is here: https://www.speedscope.app/#profileURL=https%3A%2F%2Fgist.githubusercontent.com%2Fdreid%2F197566471f39a96523f5065d19d0bf7f%2Fraw%2F3e7ec92a17bc82d40acceb1e2efcaa3ef7c8ef07%2Ftwisted-pydoctor-reversed.speedscope

Testing environment

  • Operating System and Version; paste the output of these commands:
    • on Linux, uname -a ; cat /etc/lsb-release
    • on Windows, systeminfo | Findstr /i "OS"
    • on macOS, sw_vers
  • Twisted version [e.g. 22.2.0]
    • please paste the output of twist --version and pip --freeze
  • Reactor [e.g. select, iocp]

Additional context
Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant