r-lib / vctrs

Generic programming with typed R vectors
https://vctrs.r-lib.org
Other
290 stars 66 forks source link

Combine x and ... in min, max, range #1946

Open brookslogan opened 4 months ago

brookslogan commented 4 months ago

Resolves #1372.

Only call vec_c(x, ...) if dots are nonempty, in order to stay fast in the empty case.

brookslogan commented 4 months ago

Sorry for the rewrite, fixed some commit metadata.

brookslogan commented 3 months ago

Some notes:

Small-vctr benchmarks: ```r # main x <- new_vctr(c(1,2,4)); bench::mark(min(x), min_iterations = 1e5, max_iterations = 1e5) #> # A tibble: 1 × 13 #> expression min median `itr/sec` mem_alloc `gc/sec` n_itr n_gc total_time result #> #> 1 min(x) 50.6µs 55.9µs 17597. NA 8.98 99949 51 5.68s #> # ℹ 3 more variables: memory , time , gc # this PR x <- new_vctr(c(1,2,4)); bench::mark(min(x), min_iterations = 1e5, max_iterations = 1e5) #> # A tibble: 1 × 13 #> expression min median `itr/sec` mem_alloc `gc/sec` n_itr n_gc total_time result #> #> 1 min(x) 53.3µs 55.9µs 17608. NA 8.98 99949 51 5.68s #> # ℹ 3 more variables: memory , time , gc # Without if-empty-dots optimization: x <- new_vctr(c(1,2,4)); bench::mark(min(x), min_iterations = 1e5, max_iterations = 1e5) #> # A tibble: 1 × 13 #> expression min median `itr/sec` mem_alloc `gc/sec` n_itr n_gc total_time result #> #> 1 min(x) 187µs 207µs 4737. NA 10.4 99780 220 21.1s #> # ℹ 3 more variables: memory , time , gc # Testing with short integer vectors (ALTREP seqs or not) also yielded comparable performance. ```