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

Arg match replacements (arg_match() -> arg_match0()) #1901

Merged
merged 16 commits into from
Oct 4, 2024

Conversation

rich-iannone
Copy link
Member

Continuing on the work @olivroy has been doing, this PR makes a few more replacements of arg_match() to arg_match0() to increase performance.

With a particularly demanding set of nanoplots in the table of the following code, we get a pretty decent speedup.

library(gt)

gibraltar |>
    dplyr::filter(date <= "2023-05-14") |>
    dplyr::mutate(time = as.numeric(hms::as_hms(paste0(time, ":00")))) |>
    dplyr::mutate(humidity = humidity * 100) |>
    dplyr::select(date, time, temp, humidity, wind_speed) |>
    dplyr::group_by(date) |>
    dplyr::summarize(
      time = paste(time, collapse = ","),
      temp = paste(temp, collapse = ","),
      humidity = paste(humidity, collapse = ","),
      wind_speed = paste(wind_speed, collapse = ","),
    ) |>
    dplyr::mutate(is_satsun = lubridate::wday(date) %in% c(1, 7)) |>
    gt(rowname_col = "date") |>
    tab_header(
      title = "Meteorological Summary of Gibraltar Station",
      subtitle = "Data taken from May 1-14, 2023."
    ) |>
    fmt_date(columns = stub(), date_style = "wd_m_day_year") |>
    cols_nanoplot(
      columns = temp,
      columns_x_vals = time,
      expand_x = c(0, 86400),
      autoscale = TRUE,
      new_col_name = "temperature_nano",
      new_col_label = "Temperature"
    ) |>
    cols_nanoplot(
      columns = humidity,
      columns_x_vals = time,
      expand_x = c(0, 86400),
      autoscale = TRUE,
      new_col_name = "humidity_nano",
      new_col_label = "Humidity"
    ) |>
    cols_nanoplot(
      columns = wind_speed,
      columns_x_vals = time,
      expand_x = c(0, 86400),
      autoscale = TRUE,
      new_col_name = "wind_speed_nano",
      new_col_label = "Wind Speed"
    ) |>
    cols_units(
      temperature_nano = ":degree:C",
      humidity_nano = "% (RH)",
      wind_speed_nano = "m s^-1"
    ) |>
    cols_hide(columns = is_satsun) |>
    tab_style_body(
      style = cell_fill(color = "#E5FEFE"),
      values = TRUE,
      targets = "row",
      extents = c("body", "stub")
    ) |>
    tab_style(
      style = cell_text(align = "center"),
      locations = cells_column_labels()
    )

Here are the profvis results...

...before PR:

image

...after PR:

image

@rich-iannone rich-iannone requested a review from olivroy October 4, 2024 01:44
Copy link
Collaborator

@olivroy olivroy left a comment

Choose a reason for hiding this comment

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

Pretty good! another 5-10% speedup !
lgtm!

@rich-iannone rich-iannone merged commit b75dc29 into master Oct 4, 2024
12 checks passed
@rich-iannone rich-iannone deleted the arg-match-replacements branch October 4, 2024 03:24
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