Fix performance regression related to limiting deep call stack growth (#4214)

* Use less expensive version of getCallNames() just for hashing

* Update R/conditions.R

Co-authored-by: Carson Sievert <cpsievert1@gmail.com>

---------

Co-authored-by: Carson Sievert <cpsievert1@gmail.com>
Co-authored-by: Barret Schloerke <barret@rstudio.com>
This commit is contained in:
Charlie Gao
2025-05-23 18:56:00 +01:00
committed by GitHub
parent 159e771ac7
commit 6df0bb9423

View File

@@ -75,6 +75,18 @@ getCallNames <- function(calls) {
})
}
# A stripped down version of getCallNames() that intentionally avoids deparsing expressions.
# Instead, it leaves expressions to be directly `rlang::hash()` (for de-duplication), which
# is much faster than deparsing then hashing.
getCallNamesForHash <- function(calls) {
lapply(calls, function(call) {
name <- call[[1L]]
if (is.function(name)) return("<Anonymous>")
if (typeof(name) == "promise") return("<Promise>")
name
})
}
getLocs <- function(calls) {
vapply(calls, function(call) {
srcref <- attr(call, "srcref", exact = TRUE)
@@ -144,7 +156,7 @@ getCallStackDigest <- function(callStack, warn = FALSE) {
)
}
rlang::hash(getCallNames(callStack))
rlang::hash(getCallNamesForHash(callStack))
}
saveCallStackDigest <- function(callStack) {