Skip to content

Commit

Permalink
Merge pull request #3543 from tidyverse/feature-3335-wide-performance
Browse files Browse the repository at this point in the history
Performance fixes for wide data frames #3335
  • Loading branch information
romainfrancois committed May 3, 2018
2 parents 71fdbde + 32dba91 commit 5da3d0b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@

* `sample_n()` and `sample_frac()` on grouped data frame are now faster especially for those with large number of groups (#3193, @saurfang).

* Improved performance for wide tibbles (#3335).

## Internal

* Compute variable names for joins in R (#3430).
Expand Down
5 changes: 2 additions & 3 deletions inst/include/dplyr/Result/LazySubsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace dplyr {

class LazySubsets : public ILazySubsets {
public:
LazySubsets(const DataFrame& df) : nr(df.nrows()) {
LazySubsets(const DataFrame& df) : symbol_map(df.size(), df.names()), summary_map(), data(df.size()), nr(df.nrows()) {
int nvars = df.size();
if (nvars) {
CharacterVector names = df.names();
Expand All @@ -18,8 +18,7 @@ class LazySubsets : public ILazySubsets {
if (Rf_inherits(column, "matrix")) {
stop("matrix as column is not supported");
}
symbol_map.insert(names[i]);
data.push_back(df[i]);
data[i] = df[i];
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions inst/include/tools/SymbolMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class SymbolMap {
public:
SymbolMap(): lookup(), names() {}

SymbolMap(int n, const CharacterVector& names_): lookup(n), names((SEXP)names_) {
for (int i = 0; i < n; i++) {
lookup.insert(std::make_pair(names_[i], i));
}
}

SymbolMap(const SymbolVector& names_): lookup(), names(names_) {}

SymbolMapIndex insert(const SymbolString& name) {
Expand Down

0 comments on commit 5da3d0b

Please sign in to comment.