Skip to content

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

Merged
rich-iannone merged 7 commits into
rstudio:masterfrom
olivroy:perform
Sep 27, 2024
Merged

Performance of vec_fmt_*() by avoiding checking of compatibility + coercion to tibble#1893
rich-iannone merged 7 commits into
rstudio:masterfrom
olivroy:perform

Conversation

@olivroy

@olivroy olivroy commented Sep 26, 2024

Copy link
Copy Markdown
Collaborator

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()`:

@olivroy olivroy Sep 26, 2024

Copy link
Copy Markdown
Collaborator Author

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 thread R/utils_render_common.R
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
Copy Markdown
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_*

Comment thread R/utils.R
@@ -226,9 +226,9 @@ tf_formats <- function() {

dplyr::tribble(

Copy link
Copy Markdown
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
Copy Markdown
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

@rich-iannone rich-iannone left a comment

Copy link
Copy Markdown
Member

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
@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