Opened 3 hours ago
Closed 27 minutes ago
#36242 closed Cleanup/optimization (wontfix)
NodeList render overhead with huge templates
Reported by: | Michal Čihař | Owned by: | |
---|---|---|---|
Component: | Uncategorized | Version: | 5.1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
While debugging rendering of some huge templates, I've noticed that the rendering is slower and needs more memory than necessary because of:
def render(self, context): return SafeString("".join([node.render_annotated(context) for node in self]))
which unnecessarily builds a list and then passes it to join, which could directly consume an iterable.
I will prepare a pull request with a fix.
Note:
See TracTickets
for help on using tickets.
There is nothing to fix here. A list comprehension is preferable here as
str.join()
converts to list internally anyway. It is better performance to provide a list up front.