Skip to content
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

Optimize wk_coords() for xy #160

Merged
merged 2 commits into from
Oct 10, 2022
Merged

Optimize wk_coords() for xy #160

merged 2 commits into from
Oct 10, 2022

Conversation

paleolimbot
Copy link
Owner

Closes #138; although, this doesn't change any sf-related code. Because the st_coordinates() objects are matrices, multiple copies are needed to return the object that wk_coords needs (a data frame). It is about 2x faster to do this, but the existing route wasn't all that slow to begin with and the copies require about 3x the memory.

I did keep the optimization for xy that came about as part of this, though, since that's about 3x faster if there are no empties and 2x faster if there are.

library(wk)

points <- xy(runif(1e6), runif(1e6))
bench::mark(
  wk::wk_coords(points),
  wk:::wk_coords.default(points)
)
#> # A tibble: 2 × 6
#>   expression                          min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>                     <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 wk::wk_coords(points)            4.88ms   5.57ms     179.     19.1MB     179.
#> 2 wk:::wk_coords.default(points)  16.75ms  16.96ms      58.9    26.8MB     168.

points_with_empty <- points
points_with_empty[100] <- xy(NA, NA)
bench::mark(
  wk::wk_coords(points_with_empty),
  wk:::wk_coords.default(points_with_empty)
)
#> # A tibble: 2 × 6
#>   expression                                     min  median `itr/sec` mem_alloc
#>   <bch:expr>                                <bch:tm> <bch:t>     <dbl> <bch:byt>
#> 1 wk::wk_coords(points_with_empty)            11.4ms  11.6ms      86.6    61.1MB
#> 2 wk:::wk_coords.default(points_with_empty)   18.2ms  18.4ms      54.0    53.4MB
#> # … with 1 more variable: `gc/sec` <dbl>

@codecov-commenter
Copy link

codecov-commenter commented Oct 10, 2022

Codecov Report

Base: 99.03% // Head: 99.04% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (02aaaf9) compared to base (7c86afb).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #160   +/-   ##
=======================================
  Coverage   99.03%   99.04%           
=======================================
  Files          81       81           
  Lines        5824     5837   +13     
=======================================
+ Hits         5768     5781   +13     
  Misses         56       56           
Impacted Files Coverage Δ
R/vertex-filter.R 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@paleolimbot paleolimbot merged commit db3da49 into master Oct 10, 2022
@paleolimbot paleolimbot deleted the sf-coords branch October 10, 2022 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize wk_coords() for sfc objects
2 participants