Skip to content

git_add() slow #242

@krlmlr

Description

@krlmlr

These measurements surprised me:

dir <- withr::local_tempdir()
setwd(dir)

gert::git_init()
writeLines(character(), "a.txt")
system.time(gert::git_add("."))
#>    user  system elapsed 
#>   0.019   0.002   0.105
gert::git_commit(message = "Test")
#> [1] "b49672895dc220cb508a17b1b716558b9d11fb6a"

Created on 2024-11-16 with reprex v2.1.1

Running git as an external process is much faster:

dir <- withr::local_tempdir()
setwd(dir)

gert::git_init()
writeLines(character(), "a.txt")
system.time(system("git add a.txt"))
#>    user  system elapsed 
#>   0.003   0.005   0.037
gert::git_commit(message = "Test")
#> [1] "521a3b6ee3e59e6990b37e6f61da3ed17c0fb623"

Created on 2024-11-16 with reprex v2.1.1

git2r seems to have the same problems. What is libgit2 doing there?

The implementation seems to not use the results of normalizePath(), and 20 out of the 100 milliseconds are spent in git_status(), regardless if the caller cares about the result. Need to understand why R_git_repository_add is slow.

gert::git_add
#> function (files, force = FALSE, repo = ".") 
#> {
#>     repo <- git_open(repo)
#>     info <- git_info(repo)
#>     normalizePath(file.path(info$path, files), mustWork = FALSE)
#>     force <- as.logical(force)
#>     .Call(R_git_repository_add, repo, files, force)
#>     git_status(repo = repo)
#> }
#> <bytecode: 0x113181fa8>
#> <environment: namespace:gert>

Created on 2024-11-16 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions