You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "zhengruifeng (via GitHub)" <gi...@apache.org> on 2026/07/21 01:23:47 UTC

[PR] [WIP][ML] Avoid per-leaf map for tree predictions [spark]

zhengruifeng opened a new pull request, #57389:
URL: https://github.com/apache/spark/pull/57389

   ### What changes were proposed in this pull request?
   
   Replace the transient `Map[LeafNode, Int]` used by tree leaf prediction with a transient
   integer cache on each `LeafNode`. The cache assigns the same left-to-right DFS indices once
   per tree, so prediction still traverses the tree normally and returns the existing leaf ID.
   
   
   ### Why are the changes needed?
   
   Large trees can have many leaves. When leaf prediction is used, the map creates a hash-table
   entry and boxed value for every leaf in each model copy. A single transient integer per leaf
   keeps the lookup constant-time while substantially reducing that cache's memory overhead.
   
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. Leaf IDs and their traversal order are unchanged.
   
   
   ### How was this patch tested?
   
   Not run yet. The existing decision-tree and ensemble leaf-prediction suites will be run before
   this draft is marked ready for review.
   
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Codex (GPT-5)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-58856][ML] Avoid per-leaf map for tree predictions [spark]

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on PR #57389:
URL: https://github.com/apache/spark/pull/57389#issuecomment-5365395992

   **Merge Summary:**
   - merged into master https://github.com/apache/spark/commit/bc9ee80d0de08f4cca1ac8518e4b6bee64cc544d
   - merged into branch-4.x https://github.com/apache/spark/commit/3b44d4787aec4b6a38f859c0ec4351b8ffcafbeb
   
   *Posted by `merge_spark_pr.py`*


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-58856][ML] Avoid per-leaf map for tree predictions [spark]

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng closed pull request #57389: [SPARK-58856][ML] Avoid per-leaf map for tree predictions
URL: https://github.com/apache/spark/pull/57389


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [WIP][ML] Avoid per-leaf map for tree predictions [spark]

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on PR #57389:
URL: https://github.com/apache/spark/pull/57389#issuecomment-5041458984

   Memory estimate for the leaf-prediction path (measured with JOL on Java 11 / Scala 2.13, with compressed references):
   
   | Leaves | Old Scala map cache | Stored `leafIndex` fields | Net saved |
   | ---: | ---: | ---: | ---: |
   | 1,000 | 52,480 B | 8,000 B | 44,480 B |
   | 10,000 | 464,280 B | 80,000 B | 384,280 B |
   | 100,000 | 5,302,184 B | 800,000 B | 4,502,184 B |
   
   This is approximately **40-45 bytes per leaf**, or **40-45 MiB for one million leaves**, on this JVM. The actual number will vary with JVM and Scala collection implementation.
   
   The normal `Int` field adds about 8 B per leaf even when leaf prediction is unused; the net saving above applies when `predictLeaf` would otherwise construct the map.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-58856][ML] Avoid per-leaf map for tree predictions [spark]

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on PR #57389:
URL: https://github.com/apache/spark/pull/57389#issuecomment-5435605902

   reverted in https://github.com/apache/spark/pull/58332 due to increase the risk of oom due to deep copy, will rework on this


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org