Conversation
This can reduce Frescobaldi's memory usage by several megabytes when displaying a large score since each point-and-click link is associated with its own Link object.
This further reduces memory usage since each page has an associated link.Links object, which is derived from Rectangles.
| __slots__ = ( | ||
| "fileName", "isExternal", "targetPage", "url", "tooltip", "area") | ||
|
|
||
| def __init__(self, left, top, right, bottom, url=None, tooltip=None): |
There was a problem hiding this comment.
The original code here used class attributes to set defaults for their corresponding instance attributes, but class and instance attributes can't share names when using __slots__. Since these are only ever used as instance attributes in practice, the new code simply initializes them that way to start with.
| self.tooltip = tooltip | ||
| self.url = url or "" | ||
| self.isExternal = ("://" in self.url) | ||
| self.tooltip = tooltip or "" |
There was a problem hiding this comment.
This is the most concise way to always initialize these as instance variables. (Otherwise, we would have to add else blocks to all the if statements above since they can no longer fall back on their class counterparts.)
|
I'm changing this to draft to not hold up 1.0.5, and because I promised #58 would be the last new PR for that release. But I do intend to come back to it when there's more time to test it properly. |
This PR uses Python's
__slots__mechanism to reduce the memory footprint of several data classes associated with links, cache entries, and various internal uses. The classes in question all have well-known, fixed attributes, and there are typically tens of their objects in memory at any given time, so any improvements to them would be expected to have a measurable impact. In testing I found these changes lowered Frescobaldi's memory usage by several megabytes when displaying a large score.