Entire global environment getting passed along with user-defined (global) functions in shiny
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 48/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- r
调研方向
首先使用 future.mirai::mirai_multisession 运行可复现的 Shiny 示例,并检查针对 global_function 报告的环境和对象大小。将 future_promise() 的行为与所引用的 future issue 进行比较,并确定为何包含 server 和 UI。仅传递所需对象并移除不必要的处理时间即表示完成。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
When calling a global function in a future (_promise) the entire global environment is getting passed along with the user-defined function. This, in a shiny context, also includes the server and the ui function, which depending on the apps size results in a long processing time.
This might be a regression (or promises::future_promise()'s behaviour?).
Reproduce example
library(future)
library(shiny)
library(bslib)
library(promises)
library(future.mirai)
plan(future.mirai::mirai_multisession)
some_other_global_var <- 1L
# size: 21750
# global_function <- local(function(){
# # Slow operation
# Sys.sleep(2)
# sample(1:100, 1)
# })
# size: 418991
global_function <- function(){
# Slow operation
Sys.sleep(2)
sample(1:100, 1)
}
ui <- page_fluid(
titlePanel("Extended Task Demo"),
p(
'Click the button below to perform a "calculation"',
"that takes a while to perform."
),
input_task_button("recalculate", "Recalculate"),
p(textOutput("result"))
)
server <- function(input, output) {
rand_task <- ExtendedTask$new(function() {
print(environment(global_function))
print(ls(environment(global_function)))
print(future:::objectSize(global_function))
future_promise(
{
global_function()
}, seed = 1L
)
})
bind_task_button(rand_task, "recalculate")
observeEvent(input$recalculate, {
# Invoke the extended in an observer
rand_task$invoke()
})
output$result <- renderText({
number <- rand_task$result()
paste0("Your number is ", number, ".")
})
}
shinyApp(ui, server)
Expected behavior
Passing only the needed objects.
Session information
R version 4.6.0 (2026-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 19045)
Matrix products: default
LAPACK version 3.12.1
locale:
[1] LC_COLLATE=German_Germany.utf8 LC_CTYPE=German_Germany.utf8 LC_MONETARY=German_Germany.utf8 LC_NUMERIC=C
[5] LC_TIME=German_Germany.utf8
time zone: Europe/Berlin
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] future.mirai_1.0.0 promises_1.5.0 bslib_0.11.0 future_1.70.0 shiny_1.14.0
loaded via a namespace (and not attached):
[1] jsonlite_2.0.0 compiler_4.6.0 Rcpp_1.1.1-1.1 parallel_4.6.0 later_1.4.8 jquerylib_0.1.4 globals_0.19.1 fastmap_1.2.0
[9] mime_0.13 R6_2.6.1 nanonext_1.9.1 tibble_3.3.1 mirai_2.7.1 pillar_1.11.1 rlang_1.2.0 cachem_1.1.0
[17] httpuv_1.6.17 fs_2.1.0 sass_0.4.10 otel_0.2.0 memoise_2.0.1 cli_3.6.6 withr_3.0.3 magrittr_2.0.5
[25] digest_0.6.39 rstudioapi_0.19.0 fontawesome_0.5.3 xtable_1.8-8 lifecycle_1.0.5 vctrs_0.7.3 glue_1.8.1 listenv_1.0.0
[33] codetools_0.2-20 parallelly_1.47.0 pkgconfig_2.0.3 tools_4.6.0 htmltools_0.5.9
…
*** Package versions
future 1.70.0, parallelly 1.47.0, parallel 4.6.0, globals 0.19.1, listenv 1.0.0
*** Allocations
availableCores():
system /proc/self/status
4 4
availableWorkers():
$system
[1] "localhost" "localhost" "localhost" "localhost"
*** Settings
- future.plan=<not set>
- future.fork.multithreading.enable=<not set>
- future.globals.maxSize=<not set>
- future.globals.onReference=<not set>
- future.resolve.recursive=<not set>
- future.rng.onMisuse=<not set>
- future.wait.timeout=<not set>
- future.wait.interval=<not set>
- future.wait.alpha=<not set>
- future.startup.script=<not set>
*** Backends
Number of workers: 4
List of future strategies:
1. mirai_multisession:
- args: function (..., workers = availableCores(), envir = parent.frame())
- tweaked: FALSE
- call: plan(future.mirai::mirai_multisession)
*** Basic tests
Main R session details:
pid r sysname release version nodename machine login user effective_user
1 8372 4.6.0 Windows 10 x64 build 19045 host001 x86-64 user001 user001 user001
…
- 主要语言
- R
- 星标
- 1k
- 派生
- 93
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
futureverse/future 的其他 Issue
-
The first code example in the README does not work可能已有人在做 @sean0407 于 1 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 72/100
futureverse/future#838 · 1 条评论 · 1 个 reaction ·
-
bug
难度 4/5 3-5 天 新手友好度 35/100
futureverse/future#836 · 2 条评论 ·
-
feature/resources RNG
难度 5/5 一周以上 新手友好度 35/100
futureverse/future#832 ·
-
RNG
难度 5/5 一周以上 新手友好度 38/100
futureverse/future#831 · 1 条评论 ·
-
feature request
难度 5/5 一周以上 新手友好度 30/100
futureverse/future#822 · 1 个 reaction ·
查看 futureverse/future 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 66/100
bennettoxford/opencodecounts#170 ·
-
complexity::1-low effort::1-hours priority::3-could
难度 2/5 1-3 小时 新手友好度 72/100
jumpingrivers/audit.workbench#43 ·
维护者通常 1 天内回复
-
complexity::1-low effort::1-hours priority::3-could
难度 1/5 1 小时以内 新手友好度 85/100
jumpingrivers/audit.connect#71 ·
维护者通常 1 天内回复
-
bug complexity::1-low effort::1-hours priority::2-should
难度 2/5 1-3 小时 新手友好度 68/100
jumpingrivers/audit.base#61 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
pharmaverse/admiraldev#580 ·