-
Notifications
You must be signed in to change notification settings - Fork 47
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
Faster alternative to match.arg() in digest() #139
Comments
🤷♂️ Hard to tell if it matters or if we go off into obscure territory. It is a base R function so there is probably not that much fluff. Also note that we now have a vectorized caller -- so maybe look into (Also: why does the flamegraph not show actual digesting? Am I missing something or misreading?) |
I will look into it, thanks. |
library(digest)
library(fs)
library(profile)
library(withr)
profile <- function(plan) {
local_dir(dir_create(tempfile()))
f <- getVDigest(algo = "murmur32")
replicate(1e4, f(letters)) # warmup
start <- proc.time()
replicate(1e4, f(letters))
print(proc.time() - start)
rprof <- "prof.rprof"
pprof <- "prof.pprof"
Rprof(filename = rprof)
replicate(1e4, f(letters))
Rprof(NULL)
data <- read_rprof(rprof)
write_pprof(data, pprof)
vis_pprof(pprof)
}
vis_pprof <- function(path, host = "localhost", port = NULL) {
server <- sprintf("%s:%s", host, port %||% random_port())
message("local pprof server: http://", server)
args <- c("-http", server, path)
if (on_windows()) {
shell(paste(c("pprof", args), collapse = " "))
} else {
system2(jointprof::find_pprof(), args)
}
}
random_port <- function(from = 49152L, to = 65355L) {
sample(seq.int(from = from, to = to, by = 1L), size = 1L)
}
on_windows <- function() {
tolower(Sys.info()["sysname"]) == "windows"
}
`%||%` <- function(x, y) {
if (is.null(x) || length(x) <= 0) {
y
} else {
x
}
}
profile() |
Yay! |
As with
Sys.info()
in #137,digest()
spends a noticeable amount of time onmatch.arg()
(see the flame graphs in #138). Would it be reasonable to explore cheaper alternatives to partial argument matching foralgo
anderrormode
?The text was updated successfully, but these errors were encountered: