-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-48047][SQL] Reduce memory pressure of empty TreeNode tags #46285
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
Changes from 5 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,8 +78,16 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] | |
| /** | ||
| * A mutable map for holding auxiliary information of this tree node. It will be carried over | ||
| * when this node is copied via `makeCopy`, or transformed via `transformUp`/`transformDown`. | ||
| * We lazily evaluate the `tags` since the default size of a `mutable.Map` is nonzero. This | ||
| * will reduce unnecessary memory pressure. | ||
| */ | ||
| private val tags: mutable.Map[TreeNodeTag[_], Any] = mutable.Map.empty | ||
| private[this] var _tags: mutable.Map[TreeNodeTag[_], Any] = null | ||
| private def tags: mutable.Map[TreeNodeTag[_], Any] = { | ||
| if (_tags eq null) { | ||
| _tags = mutable.Map.empty | ||
| } | ||
| _tags | ||
| } | ||
|
|
||
| /** | ||
| * Default tree pattern [[BitSet] for a [[TreeNode]]. | ||
|
|
@@ -151,7 +159,7 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] | |
| // SPARK-32753: it only makes sense to copy tags to a new node | ||
| // but it's too expensive to detect other cases likes node removal | ||
| // so we make a compromise here to copy tags to node with no tags | ||
| if (tags.isEmpty) { | ||
| if ((_tags eq null) || _tags.isEmpty) { | ||
| tags ++= other.tags | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, the map is probably pass-by reference. |
||
| } | ||
n-young-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
@@ -161,11 +169,17 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] | |
| } | ||
|
|
||
| def getTagValue[T](tag: TreeNodeTag[T]): Option[T] = { | ||
| tags.get(tag).map(_.asInstanceOf[T]) | ||
| if (_tags eq null) { | ||
n-young-db marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| None | ||
| } else { | ||
| tags.get(tag).map(_.asInstanceOf[T]) | ||
| } | ||
| } | ||
|
|
||
| def unsetTagValue[T](tag: TreeNodeTag[T]): Unit = { | ||
| tags -= tag | ||
| if (_tags ne null) { | ||
| tags -= tag | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.