Skip to content

Major speed deprecation with new object linters #226

Closed

Description

@jimhester
# 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 <- commit
  x
}

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.

Activity

  1. jimhester commented on Apr 10, 2017

    @jimhester
    MemberAuthor

    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   100
  2. fangly commented on Apr 13, 2017

    @fangly
    Contributor

    Hi Jim,
    A few comments on this promising branch:

    1. declared_s3_generics() is not found anywhere. I uncommented it locally so I could test your changes.
    2. lengths() is new to R 3.2.0 but we are using 3.1.1 in lintr.
    3. strip_names() could use unquote() (from R/path_linters.R), which itself could be improved to take several characters as input.
    4. 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.
    5. 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).
    6. 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")).
    7. Finally, perhaps generics <- c(...) can be moved one function call higher (just after the object_name_linter function definition) to avoid unnecessary computations.
  3. jimhester commented on Apr 13, 2017

    @jimhester
    MemberAuthor

    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.

  4. fangly commented on May 12, 2017

    @fangly
    Contributor

    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.

  5. fangly commented on May 18, 2017

    @fangly
    Contributor

    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?

  6. russHyde commented on Nov 13, 2018

    @russHyde
    Collaborator

    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?

  7. jimhester commented on Nov 13, 2018

    @jimhester
    MemberAuthor

    @russHyde yes please reference this issue, just to keep the links clear!

    Great to hear you have been working on this!

  8. russHyde commented on Nov 13, 2018

    @russHyde
    Collaborator

    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 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions