-
Notifications
You must be signed in to change notification settings - Fork 213
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
Performance of vec_fmt_*() by avoiding checking of compatibility + coercion to tibble #1893
Conversation
Code | ||
cols_add(tbl, x = 1, .after = 15) | ||
Condition | ||
Error in `vars_select_eval()`: |
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.
Snapshot will be improved by r-lib/tidyselect#352 when merged
# Or if we are confident that we have a compatible formatter and no rows /cols are hidden | ||
if ( | ||
col %in% colnames(data_tbl) && | ||
is_compatible_formatter( | ||
table = data_tbl, | ||
column = col, | ||
rows = rows, | ||
compat = compat | ||
skip_compat_check || | ||
( | ||
col %in% colnames(data_tbl) && | ||
is_compatible_formatter( | ||
table = data_tbl, | ||
column = col, | ||
rows = rows, | ||
compat = compat | ||
) |
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 added this to skip this check for vec_fmt_*
@@ -226,9 +226,9 @@ tf_formats <- function() { | |||
|
|||
dplyr::tribble( |
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.
Before, it seemed that tf_formats_icons()
included NAs, not sure what the impact of all this is tbh.
Now, it is:
tf_formats_icons()
[1] "c(\"✔\", \"✘\")" "c(\"●\", \"⭘\")" "c(\"■\", \"□\")" "c(\"◆\", \"◇\")" "c(\"↑\", \"↓\")" "c(\"▲\", \"▼\")"
[7] "c(\"▶\", \"◀\")"
which seems to make sense?
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.
Thanks for adding omit_na()
! Yeah, this return value is correct now but AFAICT nothing in the package uses tf_formats_icons()
(so I guess no impact).
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.
LGTM!
Summary
Hopefully, my last one.
My example is down to about 4 seconds rendering time.
The main idea is to avoid dplyr or coercion to tibble and also avoid to check for the compatibility of the formatter unnecessarily.
I realized
cols_add()
has some issues, so I fixed up the two corner cases.before = 0
and.after = last_col()
+ added tests.Also eliminated some tidyselect deprecation warnings
Related GitHub Issues and PRs
vec_*()
functions. #1888 , Improve performance of vec_fmt_*() by not building the full data #1891My profiling is now
![image](https://private-user-images.githubusercontent.com/52606734/371555941-8946feb9-ffed-400a-8770-b149ae1254c9.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg4OTU4MjcsIm5iZiI6MTczODg5NTUyNywicGF0aCI6Ii81MjYwNjczNC8zNzE1NTU5NDEtODk0NmZlYjktZmZlZC00MDBhLTg3NzAtYjE0OWFlMTI1NGM5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA3VDAyMzIwN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWZiYjA1ZGJlYmEwMTFiYjQxZThlOWNkMDBkMWQ0ZmY3ZTdhYzkxYWFiZDY2NzliOWI3NTI2NjgwOTZjODc4NTQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.pQe76f9bgwFxGGk4HnaloJJbhnYnWk_zvfxllDMFIuU)
Last possible way to improve performance would be to have a minimal
![image](https://private-user-images.githubusercontent.com/52606734/371556396-0a8bb2d6-254c-4ddb-a48a-20cdc9221e07.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg4OTU4MjcsIm5iZiI6MTczODg5NTUyNywicGF0aCI6Ii81MjYwNjczNC8zNzE1NTYzOTYtMGE4YmIyZDYtMjU0Yy00ZGRiLWE0OGEtMjBjZGM5MjIxZTA3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA3VDAyMzIwN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTUyYzQ4OTlkY2RhNjZhZTcwNTRiNmJlMmE5ZWJhNmIyMDU3MDZmZDE0Y2UxNTEyMGVhZjViNmEyZDg3OTYyOTMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.Si3mGnjfV5CU2us9CAiqV59AvPqwhmMPOm7wvaHPAT8)
gt_one_col()
function that doesn't callgt()
directlyThe
gt()
calls take about a third of time with all its checks.Also avoiding the resolvers would be great, but would require work.