-
Notifications
You must be signed in to change notification settings - Fork 1k
streamline loop in GForce j optimization #3777
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
Changes from all commits
08b4b44
8b4e1be
55f813c
ad3903e
8d0419d
ebb611a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1611,11 +1611,11 @@ replace_order = function(isub, verbose, env) { | |
| } | ||
| if (verbose) { | ||
| if (!identical(oldjsub, jsub)) | ||
| cat("lapply optimization changed j from '",deparse(oldjsub),"' to '",deparse(jsub,width.cutoff=200L),"'\n",sep="") | ||
| cat("lapply optimization changed j from '",deparse(oldjsub),"' to '",deparse(jsub,width.cutoff=200L, nlines=1L),"'\n",sep="") | ||
| else | ||
| cat("lapply optimization is on, j unchanged as '",deparse(jsub,width.cutoff=200L),"'\n",sep="") | ||
| cat("lapply optimization is on, j unchanged as '",deparse(jsub,width.cutoff=200L, nlines=1L),"'\n",sep="") | ||
| } | ||
| dotN = function(x) is.name(x) && x == ".N" # For #5760 | ||
| dotN = function(x) is.name(x) && x==".N" # For #5760. TODO: Rprof() showed dotN() may be the culprit if iterated (#1470)?; avoid the == which converts each x to character? | ||
| # FR #971, GForce kicks in on all subsets, no joins yet. Although joins could work with | ||
| # nomatch=0L even now.. but not switching it on yet, will deal it separately. | ||
| if (getOption("datatable.optimize")>=2 && !is.data.table(i) && !byjoin && length(f__) && !length(lhs)) { | ||
|
|
@@ -1643,7 +1643,9 @@ replace_order = function(isub, verbose, env) { | |
| } | ||
| if (jsub[[1L]]=="list") { | ||
| GForce = TRUE | ||
| for (ii in seq_along(jsub)[-1L]) if (!.ok(jsub[[ii]])) GForce = FALSE | ||
| for (ii in seq.int(from=2L, length.out=length(jsub)-1L)) { | ||
| if (!.ok(jsub[[ii]])) {GForce = FALSE; break} | ||
| } | ||
| } else GForce = .ok(jsub) | ||
| if (GForce) { | ||
| if (jsub[[1L]]=="list") | ||
|
|
@@ -1665,12 +1667,15 @@ replace_order = function(isub, verbose, env) { | |
| nomeanopt=FALSE # to be set by .optmean() using <<- inside it | ||
| oldjsub = jsub | ||
| if (jsub[[1L]]=="list") { | ||
| for (ii in seq_along(jsub)[-1L]) { | ||
| this_jsub = jsub[[ii]] | ||
| if (dotN(this_jsub)) next; # For #5760 | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1. And all the time was being spent in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! Maybe we should revert to the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep good thought. I tried to revert to the |
||
| # Addressing #1369, #2949 and #1974. Added is.symbol() check to handle cases where expanded function definition is used instead of function names. #1369 results in (function(x) sum(x)) as jsub[[.]] from dcast.data.table. | ||
| if (is.call(this_jsub) && is.symbol(this_jsub[[1L]]) && this_jsub[[1L]]=="mean") | ||
| jsub[[ii]] = .optmean(this_jsub) | ||
| # Addressing #1369, #2949 and #1974. This used to be 30s (vs 0.5s) with 30K elements items in j, #1470. Could have been dotN() and/or the for-looped if() | ||
| todo = sapply(jsub, function(x) { | ||
| is.call(x) && is.symbol(x[[1L]]) && x[[1L]]=="mean" | ||
| # jsub[[1]]=="list" so the first item will always be FALSE | ||
| # is.symbol() for when expanded function definition is used instead of function names; #1369 results in (function(x) sum(x)) as jsub[[.]] from dcast.data.table | ||
| }) | ||
| if (any(todo)) { | ||
| w = which(todo) | ||
| jsub[w] = lapply(jsub[w], .optmean) | ||
| } | ||
| } else if (jsub[[1L]]=="mean") { | ||
| jsub = .optmean(jsub) | ||
|
|
||
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.
x == quote(.N)works, is it any faster?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.
trying ...
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.
I guess not somewhat surprisingly (?):
Ditto if we store
qN = quote(N)beforehand for the RHS.identicalmuch worse.