Skip to content

Commit

Permalink
Memoize result value in Utilities.getremote
Browse files Browse the repository at this point in the history
Utilities.getremote is called when figuring out the URL to methods while
rendering the documentation. A profile of makedocs for Documenters docs
showed that almost half of the collected samples was inside getremote,
and in particular in the spawned process to git. This patch memoizes the
result of getremote. This should give noticeable improvements, since
this function is often often called with the same argument.
  • Loading branch information
fredrikekre committed Jun 3, 2022
1 parent 051bb4a commit 6a9e7c2
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/Utilities/Utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -512,19 +512,17 @@ function url(remote, repo, mod, file, linerange)
end
end

const GIT_REMOTE_CACHE = Dict{String,String}()

function getremote(dir::AbstractString)
remote =
try
cd(() -> readchomp(`git config --get remote.origin.url`), dir)
catch err
return get!(GIT_REMOTE_CACHE, dir) do
remote = try
readchomp(setenv(`git config --get remote.origin.url`; dir=dir))
catch
""
end
m = match(LibGit2.GITHUB_REGEX, remote)
if m === nothing
travis = get(ENV, "TRAVIS_REPO_SLUG", "")
isempty(travis) ? "" : travis
else
m[1]
m = match(LibGit2.GITHUB_REGEX, remote)
return m === nothing ? get(ENV, "TRAVIS_REPO_SLUG", "") : String(m[1])
end
end

Expand Down

0 comments on commit 6a9e7c2

Please sign in to comment.