Skip to content

Commit

Permalink
Switch datastructure Vector -> Set for algorithmic complexity (#3652)
Browse files Browse the repository at this point in the history
In the same project as #3651, this code was also having trouble
because of the rapidly growing alldeps, which would end up with
many repeated entries. Switch the data structure to fix the algorithmic
complexity here also.

(cherry picked from commit 0e0cf45)
  • Loading branch information
Keno authored and IanButterworth committed Oct 31, 2023
1 parent 09eb76c commit c16a523
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1248,19 +1248,21 @@ function precompile(ctx::Context, pkgs::Vector{PackageSpec}; internal_call::Bool
# if a list of packages is given, restrict to dependencies of given packages
if !isempty(pkgs)
pkgs_names = [p.name for p in pkgs]
function collect_all_deps(depsmap, dep, alldeps=Base.PkgId[])
append!(alldeps, depsmap[dep])
function collect_all_deps(depsmap, dep, alldeps=Set{Base.PkgId}())
for _dep in depsmap[dep]
collect_all_deps(depsmap, _dep, alldeps)
if !(_dep in alldeps)
push!(alldeps, _dep)
collect_all_deps(depsmap, _dep, alldeps)
end
end
return alldeps
end
keep = Base.PkgId[]
keep = Set{Base.PkgId}()
for dep in depsmap
dep_pkgid = first(dep)
if dep_pkgid.name in pkgs_names
push!(keep, dep_pkgid)
append!(keep, collect_all_deps(depsmap, dep_pkgid))
collect_all_deps(depsmap, dep_pkgid, keep)
end
end
for ext in keys(exts)
Expand Down

0 comments on commit c16a523

Please sign in to comment.