@@ -487,8 +487,6 @@ object RmmRapidsRetryIterator extends Logging {
487487 }
488488 }
489489 val curAttempt = attemptStack.pop()
490- // Get the info before running the split, since the attempt may be closed after splitting.
491- val attemptAsString = closeOnExcept(curAttempt)(_.toString)
492490 val splitted = try {
493491 // splitPolicy must take ownership of the argument
494492 splitPolicy(curAttempt)
@@ -497,25 +495,33 @@ object RmmRapidsRetryIterator extends Logging {
497495 // same type to provide more context for the OOM.
498496 // This looks a little odd, because we can not change the type of root exception.
499497 // Otherwise, some unit tests will fail due to the wrong exception type returned.
498+ //
499+ // Stringify the attempt lazily (only on failure) to avoid O(n) cost on the
500+ // hot path when splits succeed. The attempt has not been closed yet at this
501+ // point because splitPolicy threw before taking ownership.
500502 case go : GpuRetryOOM =>
503+ val attemptAsString = curAttempt.toString
501504 throw new GpuRetryOOM (
502505 s " GPU OutOfMemory: " +
503506 s " Current threadCountBlockedUntilReady: ${threadCountBlockedUntilReady}. " +
504507 s " Could not split the current attempt: { $attemptAsString} "
505508 ).initCause(go)
506509 case go : GpuSplitAndRetryOOM =>
510+ val attemptAsString = curAttempt.toString
507511 throw new GpuSplitAndRetryOOM (
508512 s " GPU OutOfMemory: " +
509513 s " Current threadCountBlockedUntilReady: ${threadCountBlockedUntilReady}. " +
510514 s " Could not split the current attempt: { $attemptAsString} "
511515 ).initCause(go)
512516 case co : CpuRetryOOM =>
517+ val attemptAsString = curAttempt.toString
513518 throw new CpuRetryOOM (
514519 s " CPU OutOfMemory: " +
515520 s " Current threadCountBlockedUntilReady: ${threadCountBlockedUntilReady}. " +
516521 s " Could not split the current attempt: { $attemptAsString} "
517522 ).initCause(co)
518523 case co : CpuSplitAndRetryOOM =>
524+ val attemptAsString = curAttempt.toString
519525 throw new CpuSplitAndRetryOOM (
520526 s " CPU OutOfMemory: " +
521527 s " Current threadCountBlockedUntilReady: ${threadCountBlockedUntilReady}. " +
0 commit comments