Skip to content

Commit 6df0bb9

Browse files
shikokuchuocpsievertschloerke
authored
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 <[email protected]> --------- Co-authored-by: Carson Sievert <[email protected]> Co-authored-by: Barret Schloerke <[email protected]>
1 parent 159e771 commit 6df0bb9

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

R/conditions.R

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ getCallNames <- function(calls) {
7575
})
7676
}
7777

78+
# A stripped down version of getCallNames() that intentionally avoids deparsing expressions.
79+
# Instead, it leaves expressions to be directly `rlang::hash()` (for de-duplication), which
80+
# is much faster than deparsing then hashing.
81+
getCallNamesForHash <- function(calls) {
82+
lapply(calls, function(call) {
83+
name <- call[[1L]]
84+
if (is.function(name)) return("<Anonymous>")
85+
if (typeof(name) == "promise") return("<Promise>")
86+
name
87+
})
88+
}
89+
7890
getLocs <- function(calls) {
7991
vapply(calls, function(call) {
8092
srcref <- attr(call, "srcref", exact = TRUE)
@@ -144,7 +156,7 @@ getCallStackDigest <- function(callStack, warn = FALSE) {
144156
)
145157
}
146158

147-
rlang::hash(getCallNames(callStack))
159+
rlang::hash(getCallNamesForHash(callStack))
148160
}
149161

150162
saveCallStackDigest <- function(callStack) {

0 commit comments

Comments
 (0)