You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Major speed deprecation with new object linters #226
# Run from project root directory
library(git2r)
r<- repository()
run_bench<-function(commit, code, ...) {
checkout(Filter(function(x) startsWith(x@sha, commit), commits(r))[[1]])
devtools::load_all()
x<-microbenchmark::microbenchmark(eval(code), ...)
x$expr<-commitx
}
code<- quote({lint("R/lint.R")})
x<- rbind(
run_bench("fd1ec51d", code, times=10),
run_bench("7fe7e909", code, times=10))
#> Loading lintr#> Loading lintr
summary(x)
#> expr min lq mean median uq max neval#> 1 7fe7e909 1.595453 1.599098 1.620174 1.610035 1.621247 1.714548 10#> 2 fd1ec51d 4.230639 4.302109 4.387139 4.361579 4.428514 4.681118 10
summary(x, "relative")
#> expr min lq mean median uq max neval#> 1 7fe7e909 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 10#> 2 fd1ec51d 2.651685 2.690335 2.707819 2.708996 2.731549 2.730233 10
So the current master is ~2.7 times slower than the code as of Nov. 10th. Lintr was already too slow and we can't afford to be even slower than before.
declared_s3_generics() is not found anywhere. I uncommented it locally so I could test your changes.
lengths() is new to R 3.2.0 but we are using 3.1.1 in lintr.
strip_names() could use unquote() (from R/path_linters.R), which itself could be improved to take several characters as input.
My NAMESPACE has a path like "some/path/github_lintr/NAMESPACE". After a quick look at parseNamespaceFile(), it seems like my NAMESPACE file will never be found because it expects ""some/path/lintr/NAMESPACE". I am not sure if there is a good way around non-standard locations.
I have pushed a few commits to prevent errors when NAMESPACE is not found and to look for it at the package root by default (instead of the current folder).
All tests seem to pass, but some things are still not quite right because I get some false positive lints with the new linter (and not the old linter), e.g. for "x$filename" or "pkg_name" when running: lint("R/lint.R", object_name_linter("snake_case")).
Finally, perhaps generics <- c(...) can be moved one function call higher (just after the object_name_linter function definition) to avoid unnecessary computations.
I just added the missing file with declared_s3_generics(). I can reproduce the false positives, I will look into what is going on, something's not quite right.
My plan was to eventually move the generics check to get_source_file() so it is run only once for all linters, as the information is likely useful for more than just this linter.
Your name_performance branch seem to bring a fair performance improvement, Jim. When linting a file with the default linters, it seems now only ~2x as slow as your Nov 10 reference (instead of ~2.7x).
I just did a profvis(lint("./R/lint.R")) on the name_performance branch and found that flatten_lints() takes 95% of the runtime, specifically this code: flatten_lints -> structure_lints -> flatten_list -> assign_item -> inherits. It seems like speed improvement efforts should go in this direction.
The flame graph mislead me... It looks like the object_usage_linter and make_object_linter are the time-consuming functions, unexpectedly.
Do you have any experience with the data.table package, Jim? It could perhaps provide a good performance boost since many linters use the data.frame of parsed tokens. Or do you think it would be better to just have all linters use the XML way, eventually?
I've done some modifications of the current make_object_linter that speeds up the object_length_linter (and probably some other name-related linters). All I did was move some of the conditionals around, and got some vectorisation wins. Will post a PR when I'm back home. @jimhester
: Given that there are already some code-changes associated with this issue, should I still reference this issue in the PR?
No problem, I was waiting for a plane. I'll try and run some code timings +/- the changes and versus the CRAN version using the check.R file mentioned in #318 .
Activity
jimhester commentedon Apr 10, 2017
New implementation of object_name_linter is an order of magnitude more performant than current master, https://github.com/jimhester/lintr/compare/name_performance?expand=1. Should remedy most of the slowdown.
microbenchmark( {lint("R/lint.R", object_name_linter("snake_case"))}, {lint("R/lint.R", object_name_linter_old("snake_case"))}) #> Unit: milliseconds #> expr min lq mean median uq max neval #> { lint("R/lint.R", object_name_linter2("snake_case")) } 225.9701 252.2269 265.9434 263.2129 273.7824 483.367 100 #> { lint("R/lint.R", object_name_linter("snake_case")) } 1275.5349 1360.3626 1430.6543 1425.3408 1486.9745 1735.298 100fangly commentedon Apr 13, 2017
Hi Jim,
A few comments on this promising branch:
declared_s3_generics()is not found anywhere. I uncommented it locally so I could test your changes.lengths()is new to R 3.2.0 but we are using 3.1.1 in lintr.strip_names()could useunquote()(from R/path_linters.R), which itself could be improved to take several characters as input.parseNamespaceFile(), it seems like my NAMESPACE file will never be found because it expects ""some/path/lintr/NAMESPACE". I am not sure if there is a good way around non-standard locations.lint("R/lint.R", object_name_linter("snake_case")).generics <- c(...)can be moved one function call higher (just after theobject_name_linterfunction definition) to avoid unnecessary computations.jimhester commentedon Apr 13, 2017
I just added the missing file with
declared_s3_generics(). I can reproduce the false positives, I will look into what is going on, something's not quite right.My plan was to eventually move the generics check to
get_source_file()so it is run only once for all linters, as the information is likely useful for more than just this linter.fangly commentedon May 12, 2017
Your name_performance branch seem to bring a fair performance improvement, Jim. When linting a file with the default linters, it seems now only ~2x as slow as your Nov 10 reference (instead of ~2.7x).
I just did aprofvis(lint("./R/lint.R"))on the name_performance branch and found thatflatten_lints()takes 95% of the runtime, specifically this code: flatten_lints -> structure_lints -> flatten_list -> assign_item -> inherits. It seems like speed improvement efforts should go in this direction.The flame graph mislead me... It looks like the
object_usage_linterandmake_object_linterare the time-consuming functions, unexpectedly.fangly commentedon May 18, 2017
Do you have any experience with the data.table package, Jim? It could perhaps provide a good performance boost since many linters use the data.frame of parsed tokens. Or do you think it would be better to just have all linters use the XML way, eventually?
russHyde commentedon Nov 13, 2018
I've done some modifications of the current
make_object_linterthat speeds up theobject_length_linter(and probably some other name-related linters). All I did was move some of the conditionals around, and got some vectorisation wins. Will post a PR when I'm back home. @jimhester: Given that there are already some code-changes associated with this issue, should I still reference this issue in the PR?
jimhester commentedon Nov 13, 2018
@russHyde yes please reference this issue, just to keep the links clear!
Great to hear you have been working on this!
russHyde commentedon Nov 13, 2018
No problem, I was waiting for a plane. I'll try and run some code timings +/- the changes and versus the CRAN version using the
check.Rfile mentioned in #318 .