
Inspect Worker Function Closures, Globals, and Serialization Bundle Size
Source:R/globals.R
inspect_job_globals.RdPerforms a pre-submission static and memory audit of a worker function
fun, its lexical closure environment, explicit globals, packages, and
optional args_list. Detects two common HPC failure modes before staging:
Accidental closure bloat: A function defined inside another function silently captures large local objects (such as raw datasets >50 MB) in its enclosing frame, inflating
payload.rdsfor every SLURM array task.Missing or unexported globals: Free variables or local helper functions referenced inside
funthat are neither exported bypackagesnor explicitly listed inglobals, which would fail on isolated cluster workers.
Arguments
- fun
Worker function
fun(arg)to inspect.- args_list
Optional list of task arguments included in bundle size estimation.
- globals
Optional named list of explicit worker globals.
- packages
Character vector of packages declared for worker nodes.
- size_warn_mb
Numeric threshold in MB above which captured closure objects or total estimated bundle size trigger a diagnostic warning. Default
50.
Value
An S3 object of class "slurmpilot_globals_report" containing:
ok: logical (TRUEwhen zero warnings are emitted).warnings: character vector of actionable pre-submit warnings.estimated_bundle_mb: total estimated serialization size in MB.fun_size_mb,args_size_mb,globals_size_mb: component sizes in MB.closure_objects: tibble of objects captured in non-global enclosing frames (name,class,size_mb,env_name).globals_table: tibble of explicitglobals(name,class,size_mb).missing_variables: character vector of unresolved free variables.unexported_functions: character vector of referenced functions not found in base/declaredpackagesorglobals.
Examples
make_worker <- function() {
local_offset <- 10
function(x) x + local_offset
}
rep <- inspect_job_globals(make_worker(), args_list = as.list(1:5))
print(rep)
#>
#> ── slurmpilot Pre-Submit Globals & Bundle Audit [OK]
#> • Estimated payload size: 9.13 MB (closure=0.00 MB, globals=0.00 MB, args=0.00
#> MB)
#> • Captured local closure objects: 4 | Explicit globals: 0
#> • Unresolved variables: 0 | Unexported functions: 0