Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow failures of indirect dependencies during parallel precompillation #2021

Merged

Conversation

IanButterworth
Copy link
Member

@IanButterworth IanButterworth commented Sep 15, 2020

Edit: The mechanism below has now been removed from this PR, given a better approach of allowing failures for indirect dependencies


Builds on #2018 to add the option to revert to the old-style Pkg.precompile() behavior if the user just wants/needs to precompile dependencies that are loaded.

julia> Pkg.precompile(parallel=false)
Precompiling project...
[ Info: Precompiling DifferentialEquations [0c46a032-eb83-5123-abaf-570d42b7fbaa]
[ Info: Precompiling Plots [91a5bcdd-55d7-5caf-9e0b-520d859cae80]
julia> Pkg.precompile()
Precompiling project...
[ Info: Precompiling DocStringExtensions [ffbed154-4ef7-542d-bbb7-c09d3a79fcae]
[ Info: Precompiling PoissonRandom [e409e4f3-bfea-5376-8464-e040bb5c01ab]
...
[ Info: Precompiling Plots [91a5bcdd-55d7-5caf-9e0b-520d859cae80]
...
[ Info: Precompiling DifferentialEquations [0c46a032-eb83-5123-abaf-570d42b7fbaa]

@IanButterworth
Copy link
Member Author

As a means to not block failures by packages that weren't going to be loaded anyway, sub-dependenncy compilation failures only warn now (main deps still fail).

Idea from @tkf here #2018 (comment)

Note that in this case, ColorTypes is a non-deved package that I hacked an error into

(dev) pkg> st
Status `~/Documents/GitHub/dev/Project.toml`
  [916415d5] Images v0.22.4

(dev) pkg> precompile
Precompiling project...
[ Info: Precompiling FileIO [5789e2e9-d7fb-5bc7-8068-2c6fae9b9549]
[ Info: Precompiling UnPack [3a884ed6-31ef-47d7-9d2a-63182c4928ed]
[ Info: Precompiling OffsetArrays [6fe1bfb0-de20-5000-8ca7-80f57d26f881]
[ Info: Precompiling IndirectArrays [9b13fd28-a010-5f03-acff-a1bbcff69959]
[ Info: Precompiling Compat [34da2185-b29b-5c13-b0c7-acf172513d20]
[ Info: Precompiling DataAPI [9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a]
[ Info: Precompiling WoodburyMatrices [efce3f68-66dc-5838-9240-27a6d6f5f9b6]
[ Info: Precompiling MacroTools [1914dd2f-81c6-5fcd-8719-6d5c9610ff09]
[ Info: Precompiling IntelOpenMP_jll [1d5cc7b8-4909-519e-a0f8-d0f5ad9712d0]
[ Info: Precompiling RangeArrays [b3c3ace0-ae52-54e7-9d0b-2c1406fd6b9d]
[ Info: Precompiling StaticArrays [90137ffa-7385-5640-81b9-e52037218182]
[ Info: Precompiling AbstractFFTs [621f4979-c628-5d54-868e-fcf4e3e8185c]
[ Info: Precompiling FFTW_jll [f5851436-0d7a-5f13-b9de-f02708fd171a]
[ Info: Precompiling ComputationalResources [ed09eef8-17a6-5b46-8889-db040fac31e3]
[ Info: Precompiling Distances [b4f34e82-e78d-54a5-968a-f98e89d6e8f7]
[ Info: Precompiling IdentityRanges [bbac6d45-d8f3-5730-bfe4-7a449cd117ca]
[ Info: Precompiling AxisAlgorithms [13072b0f-2c55-5437-9ae7-d433b7a33950]
[ Info: Precompiling Missings [e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28]
[ Info: Precompiling EllipsisNotation [da5c29d0-fa7d-589e-88eb-ea29b0a81949]
[ Info: Precompiling Requires [ae029012-a4dd-5104-9daa-d747884805df]
[ Info: Precompiling MappedArrays [dbb5928d-eab1-5f90-85c2-b9b0edb7c900]
[ Info: Precompiling CompilerSupportLibraries_jll [e66e0078-7015-5450-92f7-15fbd957f2ae]
[ Info: Precompiling NaNMath [77ba4419-2d1f-58cd-9bb1-8ffee604a2e3]
[ Info: Precompiling MKL_jll [856f044c-d86e-5d09-b602-aeab76dc8ba7]
[ Info: Precompiling OrderedCollections [bac558e1-5e72-5ebc-8fee-abe8a469f55d]
[ Info: Precompiling Reexport [189a3867-3050-52da-a836-e630ba90ab69]
[ Info: Precompiling TiledIteration [06e1c1a7-607b-532d-9fad-de7d9aa2abac]
[ Info: Precompiling IntervalSets [8197267c-284f-5f27-9208-e0e47529a953]
[ Info: Precompiling Ratios [c84ed2f1-dad5-54f0-aa8e-dbefe2724439]
[ Info: Precompiling CustomUnitRanges [dc8bdbbb-1ca9-579f-8c36-e416f6a65cce]
[ Info: Precompiling IterTools [c8e1da08-722c-5040-9ed9-7db0dc04731e]
[ Info: Precompiling FixedPointNumbers [53c48c17-4a7d-5ca2-90c5-79b7896eea93]
[ Info: Precompiling PaddedViews [5432bcbf-9aad-5242-b902-cca2824c8663]
[ Info: Precompiling Parameters [d96e819e-fc66-5662-9728-84c9c7592b0a]
[ Info: Precompiling DataStructures [864edb3b-99cc-5e75-8d2d-829cb0a9cfe8]
[ Info: Precompiling CatIndices [aafaddc9-749c-510e-ac4f-586e18779b91]
[ Info: Precompiling OpenSpecFun_jll [efe28fd5-8261-553b-a9e1-b2916fc3738e]
[ Info: Precompiling MosaicViews [e94cdb99-869f-56ef-bcf0-1ae2bcbe0389]
[ Info: Precompiling FFTW [7a1cc6ca-52ef-59f5-83cd-3a7055c09341]
[ Info: Precompiling SimpleTraits [699a6c99-e7fa-54fc-8d76-47d257e15c1d]
[ Info: Precompiling AxisArrays [39de3d68-74b9-583c-8d2d-e117c070f3a9]
[ Info: Precompiling SpecialFunctions [276daf66-3868-5448-9aa4-cd146d93841b]
[ Info: Precompiling ColorTypes [3da002f7-5984-5a60-b8a6-cbb66c0b333f]
[ Info: Precompiling FFTViews [4f61f5a4-77b1-5117-aa51-3ab5ef4ef0cd]
[ Info: Precompiling SortingAlgorithms [a2af1166-a08f-5f64-846c-94a0d3cef48c]
[ Info: Precompiling CoordinateTransformations [150eb455-5306-5404-9cee-2592286d6298]
[ Info: Precompiling Rotations [6038ab10-8711-5258-84ad-4b1120ba62dc]
[ Info: Precompiling Interpolations [a98d9a8b-a2ab-59e6-89dd-64a1c18fca59]
┌ Warning: Precompilation failed for sub-dependency ColorTypes [3da002f7-5984-5a60-b8a6-cbb66c0b333f]
└ @ Pkg.API ~/Documents/GitHub/Pkg.jl/src/API.jl:967
[ Info: Precompiling Colors [5ae59095-9a9b-59fe-a467-6f913c188581]
[ Info: Precompiling StatsBase [2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91]
┌ Warning: Precompilation failed for sub-dependency Colors [5ae59095-9a9b-59fe-a467-6f913c188581]
└ @ Pkg.API ~/Documents/GitHub/Pkg.jl/src/API.jl:967
[ Info: Precompiling Graphics [a2bd30eb-e257-5431-a919-1863eab51364]
[ Info: Precompiling ColorVectorSpace [c3611d14-8923-5661-9e6a-0046d554d3a4]
┌ Warning: Precompilation failed for sub-dependency Graphics [a2bd30eb-e257-5431-a919-1863eab51364]
└ @ Pkg.API ~/Documents/GitHub/Pkg.jl/src/API.jl:967
[ Info: Precompiling ImageCore [a09fc81d-aa75-5fe9-8630-4744c3626534]
┌ Warning: Precompilation failed for sub-dependency ColorVectorSpace [c3611d14-8923-5661-9e6a-0046d554d3a4]
└ @ Pkg.API ~/Documents/GitHub/Pkg.jl/src/API.jl:967
┌ Warning: Precompilation failed for sub-dependency ImageCore [a09fc81d-aa75-5fe9-8630-4744c3626534]
└ @ Pkg.API ~/Documents/GitHub/Pkg.jl/src/API.jl:967
[ Info: Precompiling ImageAxes [2803e5a7-5153-5ecf-9a86-9b4c37f5f5ac]
[ Info: Precompiling ImageDistances [51556ac3-7006-55f5-8cb3-34580c88182d]
[ Info: Precompiling ImageMorphology [787d08f9-d448-5407-9aad-5290dd7ab264]
[ Info: Precompiling ImageTransformations [02fcd773-0e25-5acc-982a-7f6622650795]
[ Info: Precompiling ImageShow [4e3cecfd-b093-5904-9786-8bbb286a6a31]
┌ Warning: Precompilation failed for sub-dependency ImageMorphology [787d08f9-d448-5407-9aad-5290dd7ab264]
└ @ Pkg.API ~/Documents/GitHub/Pkg.jl/src/API.jl:967
┌ Warning: Precompilation failed for sub-dependency ImageDistances [51556ac3-7006-55f5-8cb3-34580c88182d]
└ @ Pkg.API ~/Documents/GitHub/Pkg.jl/src/API.jl:967
┌ Warning: Precompilation failed for sub-dependency ImageTransformations [02fcd773-0e25-5acc-982a-7f6622650795]
└ @ Pkg.API ~/Documents/GitHub/Pkg.jl/src/API.jl:967
[ Info: Precompiling ImageContrastAdjustment [f332f351-ec65-5f6a-b3d1-319c6670881a]
┌ Warning: Precompilation failed for sub-dependency ImageAxes [2803e5a7-5153-5ecf-9a86-9b4c37f5f5ac]
└ @ Pkg.API ~/Documents/GitHub/Pkg.jl/src/API.jl:967
[ Info: Precompiling ImageMetadata [bc367c6b-8a6b-528e-b4bd-a4b897500b49]
┌ Warning: Precompilation failed for sub-dependency ImageShow [4e3cecfd-b093-5904-9786-8bbb286a6a31]
└ @ Pkg.API ~/Documents/GitHub/Pkg.jl/src/API.jl:967
┌ Warning: Precompilation failed for sub-dependency ImageContrastAdjustment [f332f351-ec65-5f6a-b3d1-319c6670881a]
└ @ Pkg.API ~/Documents/GitHub/Pkg.jl/src/API.jl:967
┌ Warning: Precompilation failed for sub-dependency ImageMetadata [bc367c6b-8a6b-528e-b4bd-a4b897500b49]
└ @ Pkg.API ~/Documents/GitHub/Pkg.jl/src/API.jl:967
[ Info: Precompiling ImageFiltering [6a3955dd-da59-5b1f-98d4-e7296123deb5]
┌ Warning: Precompilation failed for sub-dependency ImageFiltering [6a3955dd-da59-5b1f-98d4-e7296123deb5]
└ @ Pkg.API ~/Documents/GitHub/Pkg.jl/src/API.jl:967
[ Info: Precompiling ImageQualityIndexes [2996bd0c-7a13-11e9-2da2-2f5ce47296a9]
┌ Warning: Precompilation failed for sub-dependency ImageQualityIndexes [2996bd0c-7a13-11e9-2da2-2f5ce47296a9]
└ @ Pkg.API ~/Documents/GitHub/Pkg.jl/src/API.jl:967
[ Info: Precompiling Images [916415d5-f1e6-5110-898d-aaa5f9f070e0]
ERROR: TaskFailedException

    nested task error: Failed to precompile Images [916415d5-f1e6-5110-898d-aaa5f9f070e0] to /Users/ian/.julia/compiled/v1.6/Images/H8Vxc_vWD4f.ji.
    Stacktrace:
     [1] macro expansion
       @ ~/Documents/GitHub/Pkg.jl/src/API.jl:965 [inlined]
     [2] (::Pkg.API.var"#203#213"{Pkg.API.var"#is_stale#212", Dict{Base.UUID, Bool}, Dict{Base.UUID, Base.Event}, Vector{Base.PkgId}, Base.Semaphore, Base.PkgId, Int64, String, Vector{String}})()
       @ Pkg.API ./task.jl:392
    
    caused by: Failed to precompile Images [916415d5-f1e6-5110-898d-aaa5f9f070e0] to /Users/ian/.julia/compiled/v1.6/Images/H8Vxc_vWD4f.ji.
    Stacktrace:
     [1] error(s::String)
       @ Base ./error.jl:33
     [2] compilecache(pkg::Base.PkgId, path::String)
       @ Base ./loading.jl:1262
     [3] #205
       @ ~/Documents/GitHub/Pkg.jl/src/API.jl:960 [inlined]
     [4] redirect_stderr(f::Pkg.API.var"#205#215"{Base.PkgId, String}, stream::Base.DevNull)
       @ Base ./stream.jl:1224
     [5] macro expansion
       @ ~/Documents/GitHub/Pkg.jl/src/API.jl:959 [inlined]
     [6] (::Pkg.API.var"#203#213"{Pkg.API.var"#is_stale#212", Dict{Base.UUID, Bool}, Dict{Base.UUID, Base.Event}, Vector{Base.PkgId}, Base.Semaphore, Base.PkgId, Int64, String, Vector{String}})()
       @ Pkg.API ./task.jl:392
Stacktrace:
  [1] sync_end(c::Channel{Any})
    @ Base ./task.jl:350
  [2] macro expansion
    @ ./task.jl:369 [inlined]
  [3] precompile(ctx::Pkg.Types.Context; parallel::Bool)
    @ Pkg.API ~/Documents/GitHub/Pkg.jl/src/API.jl:936
  [4] precompile
    @ ~/Documents/GitHub/Pkg.jl/src/API.jl:897 [inlined]
  [5] #precompile#195
    @ ~/Documents/GitHub/Pkg.jl/src/API.jl:895 [inlined]
  [6] precompile()
    @ Pkg.API ~/Documents/GitHub/Pkg.jl/src/API.jl:895
  [7] do_cmd!(command::Pkg.REPLMode.Command, repl::REPL.LineEditREPL)
    @ Pkg.REPLMode ~/Documents/GitHub/Pkg.jl/src/REPLMode/REPLMode.jl:400
  [8] do_cmd(repl::REPL.LineEditREPL, input::String; do_rethrow::Bool)
    @ Pkg.REPLMode ~/Documents/GitHub/Pkg.jl/src/REPLMode/REPLMode.jl:381
  [9] do_cmd
    @ ~/Documents/GitHub/Pkg.jl/src/REPLMode/REPLMode.jl:376 [inlined]
 [10] (::Pkg.REPLMode.var"#24#27"{REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::IOBuffer, ok::Bool)
    @ Pkg.REPLMode ~/Documents/GitHub/Pkg.jl/src/REPLMode/REPLMode.jl:545
 [11] #invokelatest#2
    @ ./essentials.jl:707 [inlined]
 [12] invokelatest
    @ ./essentials.jl:706 [inlined]
 [13] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/REPL/src/LineEdit.jl:2434
 [14] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:1124
 [15] (::REPL.var"#44#49"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL ./task.jl:392

@IanButterworth IanButterworth changed the title Provide parallel kwarg in precompile to select previous behavior Provide previous precompile via kwarg, and allow failures of sub-dependencies during parallel Sep 16, 2020
src/API.jl Outdated Show resolved Hide resolved
src/API.jl Outdated Show resolved Hide resolved
@IanButterworth
Copy link
Member Author

Requires JuliaLang/julia#37596

@tkf
Copy link
Member

tkf commented Sep 16, 2020

Quoting the time-complexity consideration I commented in JuliaLang/julia#37596 (comment)

It means that Pkg.precompile has quadratic time-complexity when an error happens. I think it's reasonable to optimize for the happy path for now given that doing this "correctly" is presumably much more challenging #2018 (comment). Also, we can still use using TheProblematicPackage to get the precompilation error in linear time.

@IanButterworth
Copy link
Member Author

Do we think this and the julia PR is good as it stands?

src/API.jl Outdated Show resolved Hide resolved
@IanButterworth IanButterworth changed the title Provide previous precompile via kwarg, and allow failures of sub-dependencies during parallel Allow failures of sub-dependencies during parallel precompillation Sep 17, 2020
@IanButterworth IanButterworth changed the title Allow failures of sub-dependencies during parallel precompillation Allow failures of indirect dependencies during parallel precompillation Sep 17, 2020
@IanButterworth IanButterworth force-pushed the ib/parallel_precomp_optional branch from 906f46e to e227bc2 Compare September 17, 2020 23:56
src/API.jl Outdated Show resolved Hide resolved
src/API.jl Outdated
Comment on lines 907 to 910
# stdlibs that aren't loaded might need precompiling if not part of sysimage
function is_stdlib_and_loaded(pkg::Base.PkgId)
return Pkg.Operations.is_stdlib(pkg.uuid) && Base.root_module_exists(pkg)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/API.jl Outdated Show resolved Hide resolved
Co-authored-by: Takafumi Arakaki <takafumi.a@gmail.com>
src/API.jl Outdated Show resolved Hide resolved
src/API.jl Outdated Show resolved Hide resolved
IanButterworth and others added 2 commits September 18, 2020 18:59
Co-authored-by: Takafumi Arakaki <takafumi.a@gmail.com>
@IanButterworth
Copy link
Member Author

IanButterworth commented Sep 18, 2020

Now also requires JuliaLang/julia#37652 for in_sysimage

@fredrikekre fredrikekre reopened this Sep 22, 2020
src/API.jl Outdated Show resolved Hide resolved
src/API.jl Outdated Show resolved Hide resolved
src/Pkg.jl Outdated Show resolved Hide resolved
src/Pkg.jl Outdated Show resolved Hide resolved
IanButterworth and others added 2 commits September 22, 2020 10:04
Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>
Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>
@IanButterworth
Copy link
Member Author

That CI failure seems to be a connection glitch https://travis-ci.com/github/JuliaLang/Pkg.jl/jobs/389278321#L419

@IanButterworth
Copy link
Member Author

Passed now. Just the docs that auto-cancelled with the first fail

src/API.jl Outdated Show resolved Hide resolved
src/API.jl Outdated Show resolved Hide resolved
Co-authored-by: Takafumi Arakaki <takafumi.a@gmail.com>
src/API.jl Outdated Show resolved Hide resolved
@IanButterworth
Copy link
Member Author

IanButterworth commented Sep 22, 2020

Some optimizations have been added to TOMLCache handling to speed up the no-op case, based on slack discussion with @staticfloat and @KristofferC

A no-op, now looks like this, where there are 215 deps in the manifest:
(This is with Pkg dev-ed and not in the sysimage, so likely to be fast first time in a normal setup (?))

(dev) pkg> st
Status `.../dev/Project.toml`
  [0c46a032] DifferentialEquations v6.15.0
  [916415d5] Images v0.22.4
  [91a5bcdd] Plots v1.6.6

julia> @time Pkg.precompile()
Precompiling project...
  1.184606 seconds (1.05 M allocations: 74.611 MiB, 0.78% gc time)

julia> @time Pkg.precompile()
Precompiling project...
  0.610128 seconds (851.07 k allocations: 63.627 MiB, 3.08% gc time)

julia> @time Pkg.precompile()
Precompiling project...
  0.585737 seconds (851.07 k allocations: 63.627 MiB, 0.77% gc time)

julia> @time Pkg.precompile()
Precompiling project...
  0.586784 seconds (851.07 k allocations: 63.627 MiB, 1.52% gc time)

@IanButterworth
Copy link
Member Author

I think this is good to go now, along with #2033 to allow opting-in to make it automatic after the common pkg calls

@IanButterworth IanButterworth mentioned this pull request Sep 23, 2020
any_dep_recompiled = any(map(dep_uuid->was_recompiled[dep_uuid], pkg_dep_uuid_lists[i]))
if !errored && (any_dep_recompiled || is_stale(paths, sourcepath))
any_dep_recompiled = any(map(dep->was_recompiled[dep], deps))
if !errored && (any_dep_recompiled || _is_stale(paths, sourcepath, toml_c))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are going to rely on Base.TOMLCache to be "async-safe" (which is, BTW, pretty easy to break; e.g., a @debug can ruin this property), I don't think it's necessary to move _is_stale out. It's actually where closure is useful. Although there is nothing bad in factoring out _is_stale this way.

Copy link
Member Author

@IanButterworth IanButterworth Sep 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staticfloat did some probing of the list of toml files that were accessed when no tomlcaches were provided, and it was just the current environment manifest and project files (2 files), so the thinking was that it was async safe as it's read-only after the first use in the for-loop. Would that be broken by @debug?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good to resolve this, and merge, to fix #2035

@fredrikekre @KristofferC

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parsed_toml(cache::TOMLCache, project_file::String) reuses TOML.Parser: https://github.com/JuliaLang/julia/blob/2a36f83ce9bdfd17c572472f60b830aedcf181f0/base/loading.jl#L174-L175

So, for example, TOML.parse(::TOML.Parser) has to be async-safe. It probably is and likely be so forever but relying on "likely" is not the best approach especially in concurrent programming. For example, maybe somebody will implement TOML.parse(::IO) at some point and the parsing can happen in a streaming fashion.

(It's also a bit concerning that the I/O read(project_file, String) is happening in get! but that's probably handled by the .age field in Dict.)

Anyway, I don't think my comment should block this PR. We can fix it in Base if we want.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, merging this as-is seems like the thing to do for now

src/API.jl Outdated Show resolved Hide resolved
@fredrikekre fredrikekre mentioned this pull request Sep 23, 2020
@staticfloat staticfloat merged commit 3912236 into JuliaLang:master Sep 23, 2020
@IanButterworth IanButterworth deleted the ib/parallel_precomp_optional branch September 23, 2020 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants