RConsortium / S7

S7: a new OO system for R
https://rconsortium.github.io/S7
Other
386 stars 32 forks source link

rewrite `prop()` in C #395

Closed t-kalinowski closed 8 months ago

t-kalinowski commented 8 months ago

Addresses #363

t-kalinowski commented 8 months ago

Slightly over a 10x speed-up by moving prop() to C for the most simple case.

library(S7)

foo <- new_class("foo", properties = list(xyz = class_double))
obj <- foo(1)
propr <- S7:::propr
print(plot(print(df <- bench::mark(
  c = prop(obj, "xyz"),
  r = propr(obj, "xyz")
))))
#> # A tibble: 2 × 13
#>   expression      min   median `itr/sec` mem_alloc `gc/sec` n_itr  n_gc
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl> <int> <dbl>
#> 1 c          205.01ns 287.02ns  3215873.        0B      0   10000     0
#> 2 r            3.77µs   4.14µs   227757.    39.8KB     45.6  9998     2
#> # ℹ 5 more variables: total_time <bch:tm>, result <list>, memory <list>,
#> #   time <list>, gc <list>
#> Loading required namespace: tidyr

Created on 2023-12-17 with reprex v2.0.2

t-kalinowski commented 8 months ago

better to merge this and iterate in future PRs

I'd vote to merge now, since it's immediately beneficial, and then we can continue to iterate in future PRs (also, it's looking like prop<- is going to involve some discussion, and would probably be better in its own PR).

hadley commented 8 months ago

Sounds good. Can you please add a bullet to news? (We wouldn't normally because it's not user facing, but it'll remind us to discuss in the next WG meeting)