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

Prefer vctrs functions over slower base R equivalents #1114

Merged
merged 7 commits into from
Apr 18, 2023
Merged

Conversation

krlmlr
Copy link
Member

@krlmlr krlmlr commented Apr 17, 2023

for performance.

@github-actions
Copy link
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 940010d is merged into main:

  •   :ballot_box_with_check:cache_applying: 205ms -> 205ms [-1.27%, +1.88%]
  •   :rocket:cache_recording: 942ms -> 923ms [-2.54%, -1.55%]
  •   :rocket:without_cache: 1.91s -> 1.87s [-3.24%, -1.25%]

Further explanation regarding interpretation and methodology can be found in the documentation.

@krlmlr
Copy link
Member Author

krlmlr commented Apr 17, 2023

Next in line: replacing x[idx, ] with vec_slice(x, idx) .

@krlmlr
Copy link
Member Author

krlmlr commented Apr 17, 2023

And split() by vec_split() . Both operations are use a lot, the vctrs version is faster by a factor.

@github-actions
Copy link
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 0c4187c is merged into main:

  •   :ballot_box_with_check:cache_applying: 192ms -> 194ms [-1.14%, +3.68%]
  •   :rocket:cache_recording: 921ms -> 907ms [-2.2%, -0.79%]
  •   :rocket:without_cache: 1.91s -> 1.86s [-2.76%, -1.92%]

Further explanation regarding interpretation and methodology can be found in the documentation.

@lorenzwalthert
Copy link
Collaborator

I still see the definition of bind_rows() and some uses in the source code. Is that intentional or did you want to replace all occurrences?
Screenshot 2023-04-17 at 17 08 04

@krlmlr
Copy link
Member Author

krlmlr commented Apr 17, 2023

Gone now.

@krlmlr
Copy link
Member Author

krlmlr commented Apr 17, 2023

Will conflict with #1112, but I can handle that.

@codecov-commenter
Copy link

codecov-commenter commented Apr 17, 2023

Codecov Report

Merging #1114 (9efa6d5) into main (0592e8e) will decrease coverage by 0.01%.
The diff coverage is 90.66%.

❗ Current head 9efa6d5 differs from pull request most recent head e4435d6. Consider uploading reports for the commit e4435d6 to get more accurate results

@@            Coverage Diff             @@
##             main    #1114      +/-   ##
==========================================
- Coverage   91.07%   91.07%   -0.01%     
==========================================
  Files          46       46              
  Lines        2713     2701      -12     
==========================================
- Hits         2471     2460      -11     
+ Misses        242      241       -1     
Impacted Files Coverage Δ
R/relevel.R 49.29% <28.57%> (ø)
R/utils-navigate-nest.R 81.48% <50.00%> (ø)
R/compat-dplyr.R 92.59% <66.66%> (-0.27%) ⬇️
R/compat-tidyr.R 100.00% <100.00%> (ø)
R/detect-alignment-utils.R 97.18% <100.00%> (ø)
R/detect-alignment.R 97.84% <100.00%> (+0.04%) ⬆️
R/indent.R 100.00% <100.00%> (ø)
R/nest.R 100.00% <100.00%> (ø)
R/parse.R 87.80% <100.00%> (ø)
R/reindent.R 100.00% <100.00%> (ø)
... and 11 more

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

@github-actions
Copy link
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 0592e8e is merged into main:

  •   :ballot_box_with_check:cache_applying: 242ms -> 244ms [-0.53%, +2.16%]
  •   :rocket:cache_recording: 1.05s -> 849ms [-19.98%, -19.03%]
  •   :rocket:without_cache: 2.15s -> 1.62s [-25.2%, -24.11%]

Further explanation regarding interpretation and methodology can be found in the documentation.

@github-actions
Copy link
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 0592e8e is merged into main:

  •   :ballot_box_with_check:cache_applying: 187ms -> 191ms [-0.04%, +3.45%]
  •   :rocket:cache_recording: 928ms -> 665ms [-29.21%, -27.39%]
  •   :rocket:without_cache: 1.92s -> 1.24s [-35.94%, -35.27%]

Further explanation regarding interpretation and methodology can be found in the documentation.

@github-actions
Copy link
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 0592e8e is merged into main:

  •   :ballot_box_with_check:cache_applying: 200ms -> 203ms [-0.59%, +3.17%]
  •   :rocket:cache_recording: 942ms -> 674ms [-29.11%, -27.87%]
  •   :rocket:without_cache: 1.93s -> 1.25s [-35.56%, -34.97%]

Further explanation regarding interpretation and methodology can be found in the documentation.

@github-actions
Copy link
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 0592e8e is merged into main:

  • ❗🐌cache_applying: 229ms -> 233ms [+0.05%, +2.84%]
  •   :rocket:cache_recording: 1.02s -> 752ms [-27.12%, -26.01%]
  •   :rocket:without_cache: 2.11s -> 1.42s [-33.23%, -32.34%]

Further explanation regarding interpretation and methodology can be found in the documentation.

@github-actions
Copy link
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 0592e8e is merged into main:

  • ❗🐌cache_applying: 202ms -> 207ms [+0.06%, +4.17%]
  •   :rocket:cache_recording: 951ms -> 679ms [-29.21%, -28.07%]
  •   :rocket:without_cache: 1.94s -> 1.26s [-35.5%, -34.65%]

Further explanation regarding interpretation and methodology can be found in the documentation.

@github-actions
Copy link
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 0592e8e is merged into main:

  •   :ballot_box_with_check:cache_applying: 321ms -> 317ms [-2.86%, +0.52%]
  •   :rocket:cache_recording: 1.52s -> 1.1s [-28.7%, -26.34%]
  •   :rocket:without_cache: 3.15s -> 2.1s [-33.97%, -32.59%]

Further explanation regarding interpretation and methodology can be found in the documentation.

@krlmlr
Copy link
Member Author

krlmlr commented Apr 17, 2023

Finally green.

Force-pushed, with meaningful individual commits.

@github-actions
Copy link
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 0592e8e is merged into main:

  • ❗🐌cache_applying: 265ms -> 266ms [+0.06%, +1.14%]
  •   :rocket:cache_recording: 1.04s -> 779ms [-25.7%, -23.97%]
  •   :rocket:without_cache: 2.06s -> 1.41s [-32.64%, -30.36%]

Further explanation regarding interpretation and methodology can be found in the documentation.

@krlmlr
Copy link
Member Author

krlmlr commented Apr 17, 2023

Super-green. Greener than green.

@krlmlr krlmlr changed the title Prefer vec_rbind() over bind_rows() Prefer vctrs functions over slower base R equivalents Apr 17, 2023
@lorenzwalthert
Copy link
Collaborator

Great @krlmlr. I was wondering: Do we want to replace all / more of [ with vec_slice()? Because I see more cases, some of them (like in lag()) get called on every nest, so there might still be room for improvement.

@krlmlr
Copy link
Member Author

krlmlr commented Apr 18, 2023

Good catch! [ on a vector is fast, but we do gain a lot with data frames. Expecting another boost with the last commit.

@github-actions
Copy link
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if e5ecef7 is merged into main:

  •   :ballot_box_with_check:cache_applying: 217ms -> 221ms [-0.27%, +3.5%]
  •   :rocket:cache_recording: 1.01s -> 738ms [-27.61%, -26.83%]
  •   :rocket:without_cache: 2.06s -> 1.36s [-34.31%, -33.82%]

Further explanation regarding interpretation and methodology can be found in the documentation.

Copy link
Collaborator

@lorenzwalthert lorenzwalthert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. 🥳

@lorenzwalthert lorenzwalthert merged commit 15a5f5b into main Apr 18, 2023
@lorenzwalthert lorenzwalthert deleted the f-rbind branch April 18, 2023 08:14
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.

3 participants