Skip to content

Proposal: _fast variants for lower-overhead Julia calls #286

Description

@BjarkeHautop

The current overhead for me calling julia_call("sqrt", 2) is ~7μs. Providing a _fast equivalent stripping it of some QoL stuff reduces this overhead to ~4.5μs for me. Here is the code I added:

julia_do.call_fast <- julia$do.call_fast <- function(func_name, arg_list) {
    r <- .julia$do.call_(list(fname = func_name, args = arg_list, need_return = "R", show_value = FALSE))
    if (inherits(r, "error")) stop(r)
    r
}

julia_call_fast <- julia$call_fast <- function(func_name, ...)
    julia$do.call_fast(func_name, list(...))

And benchmark:

bench::mark(julia_call("sqrt", 2), julia_call_fast("sqrt", 2))[, 1:3]
# A tibble: 2 × 3
  expression                          min   median
  <bch:expr>                     <bch:tm> <bch:tm>
1 "julia_call(\"sqrt\", 2)"         6.4µs    7.0µs
2 "julia_call_fast(\"sqrt\", 2)"    4.1µs    4.5µs

Happy to make a PR if you want these added _fast equivalents. I also understand if saving ~2.5μs per call isn't worth the new API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions