-
Notifications
You must be signed in to change notification settings - Fork 32
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
rewrite prop()
in C
#395
rewrite prop()
in C
#395
Conversation
7b60910
to
94543f8
Compare
94543f8
to
beebb94
Compare
Slightly over a 10x speed-up by moving 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Do you think it's worth iterating in this PR for bit longer (including a bit of thought about how to track performance more broadly), or it's better to merge this an iterate in future PRs?
} | ||
|
||
static inline | ||
Rboolean inherits2(SEXP object, const char* name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea!
if(has_name(properties, name_char)) | ||
return value; | ||
|
||
if (S7_class == R_NilValue && | ||
is_s7_class(object) && ( | ||
name_sym == sym_name || | ||
name_sym == sym_parent || | ||
name_sym == sym_package || | ||
name_sym == sym_properties || | ||
name_sym == sym_abstract || | ||
name_sym == sym_constructor || | ||
name_sym == sym_validator | ||
)) | ||
return value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it's worth implementing prop_names()
and prop_exists()
at the same time because that might influence the design of name validation?
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 |
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) |
9faafb8
to
b8422a1
Compare
Addresses #363