Fixed #34521 -- Added __slots__ to several template classes. #18649
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Trac ticket number
ticket-34521
Branch description
Following this forum discussion, this PR is a repeat of #16805, but limited to just
Node
classes andNodeList
, to deal with compatibility concerns. According to my benchmark, this change saves about 20% of the memory for templates and speeds up rendering by up to 6%.Because attributes named in
__slots__
cannot be class attributes,Node.token
andNodeList.contains_nontext
have been converted to instance attributes, defined in__init__()
. This change requires that all their subclasses callsuper().__init__()
, which was not the case previously.Checklist
main
branch.