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

Performance of vec_fmt_*() by avoiding checking of compatibility + coercion to tibble #1893

Merged
merged 7 commits into from
Sep 27, 2024

Conversation

olivroy
Copy link
Collaborator

@olivroy olivroy commented Sep 26, 2024

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

My profiling is now
image

Last possible way to improve performance would be to have a minimal gt_one_col() function that doesn't call gt() directly
image

The gt() calls take about a third of time with all its checks.

Also avoiding the resolvers would be great, but would require work.

Code
cols_add(tbl, x = 1, .after = 15)
Condition
Error in `vars_select_eval()`:
Copy link
Collaborator Author

@olivroy olivroy Sep 26, 2024

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

Comment on lines +111 to +121
# 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
)
Copy link
Collaborator Author

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(
Copy link
Collaborator Author

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?

Copy link
Member

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).

@rich-iannone rich-iannone self-requested a review September 26, 2024 22:10
Copy link
Member

@rich-iannone rich-iannone left a comment

Choose a reason for hiding this comment

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

LGTM!

@rich-iannone rich-iannone merged commit 7e265f7 into rstudio:master Sep 27, 2024
12 checks passed
@olivroy olivroy deleted the perform branch September 27, 2024 12:59
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.

2 participants