-
Notifications
You must be signed in to change notification settings - Fork 214
Improve performance of render_html()
#1470
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
Improve performance of render_html()
#1470
Conversation
@@ -1063,419 +1063,400 @@ create_body_component_h <- function(data) { | |||
} | |||
|
|||
# Create a default vector of row span values for group labels as a column | |||
row_span_vals <- rep_len(list(NULL), n_cols_total) | |||
row_span_vals <- rep_len(NA_integer_, n_cols_total) |
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.
Using vectors instead of lists is much nicer to work with and also faster.
group_idx[seq(start, end)] <- i | ||
group_ids[seq(start, end)] <- groups_rows_df$group_id[[i]] | ||
} | ||
groups_list <- as.list(groups_rows_df) |
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.
Accessing fields from a list is much faster than fields of a data frame
@mgirlich This is great work and I really appreciate it! The only problem I can see is that adding From a quick search, |
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!
This was added in PR rstudio#1470 but used px instead of pt causing the problem to persist
Summary
Rendering slightly bigger tables (e.g. 50k rows) as HTML is very slow. The two main culprits are
create_body_component_h()
and {htmltools} (in particulartagWrite()
but also creating the tags themself).Two small benchmarks
Checklist
testthat
unit tests totests/testthat
for any new functionality.Notes
create_body_component_h()
is quite huge. I think it would make sense to split parts of it into separate functions, e.g. a function for the group headings, the summaries, the data itself. I didn't do this as I didn't want to change the style too much.The PR is probably quite a bit easier to understand by looking at the commits one by one. Otherwise the changes are hard to follow.
There are a couple of places in
render_row_data()
that deal with spaces and creating HTML. This feels quite tedious and error prone. It would be great to use {htmltools} for such a task but this would require to increase the performance of {htmltools} much more.I also opened an issue in {htmltools} regarding the performance