@@ -769,7 +769,7 @@ function _include_from_serialized(path::String, depmods::Vector{Any})
769769 return restored
770770end
771771
772- function _tryrequire_from_serialized (modkey:: PkgId , build_id:: UInt64 , modpath:: Union{Nothing, String} )
772+ function _tryrequire_from_serialized (modkey:: PkgId , build_id:: UInt64 , modpath:: Union{Nothing, String} , depth :: Int = 0 )
773773 if root_module_exists (modkey)
774774 M = root_module (modkey)
775775 if PkgId (M) == modkey && module_build_id (M) === build_id
@@ -780,7 +780,7 @@ function _tryrequire_from_serialized(modkey::PkgId, build_id::UInt64, modpath::U
780780 modpath = locate_package (modkey)
781781 modpath === nothing && return nothing
782782 end
783- mod = _require_search_from_serialized (modkey, String (modpath))
783+ mod = _require_search_from_serialized (modkey, String (modpath), depth )
784784 get! (PkgOrigin, pkgorigins, modkey). path = modpath
785785 if ! isa (mod, Bool)
786786 for callback in package_callbacks
@@ -821,10 +821,14 @@ function _require_from_serialized(path::String)
821821 return _include_from_serialized (path, depmods)
822822end
823823
824+ # use an Int counter so that nested @time_imports calls all remain open
825+ const TIMING_IMPORTS = Threads. Atomic {Int} (0 )
826+
824827# returns `true` if require found a precompile cache for this sourcepath, but couldn't load it
825828# returns `false` if the module isn't known to be precompilable
826829# returns the set of modules restored if the cache load succeeded
827- function _require_search_from_serialized (pkg:: PkgId , sourcepath:: String )
830+ function _require_search_from_serialized (pkg:: PkgId , sourcepath:: String , depth:: Int = 0 )
831+ t_before = time_ns ()
828832 paths = find_all_in_cache_path (pkg)
829833 for path_to_try in paths:: Vector{String}
830834 staledeps = stale_cachefile (sourcepath, path_to_try)
@@ -840,7 +844,7 @@ function _require_search_from_serialized(pkg::PkgId, sourcepath::String)
840844 dep = staledeps[i]
841845 dep isa Module && continue
842846 modpath, modkey, build_id = dep:: Tuple{String, PkgId, UInt64}
843- dep = _tryrequire_from_serialized (modkey, build_id, modpath)
847+ dep = _tryrequire_from_serialized (modkey, build_id, modpath, depth + 1 )
844848 if dep === nothing
845849 @debug " Required dependency $modkey failed to load from cache file for $modpath ."
846850 staledeps = true
@@ -855,6 +859,13 @@ function _require_search_from_serialized(pkg::PkgId, sourcepath::String)
855859 if isa (restored, Exception)
856860 @debug " Deserialization checks failed while attempting to load cache from $path_to_try " exception= restored
857861 else
862+ if TIMING_IMPORTS[] > 0
863+ elapsed = round ((time_ns () - t_before) / 1e6 , digits = 1 )
864+ tree_prefix = depth == 0 ? " " : " $(" " ^ (depth- 1 )) ┌ "
865+ print (" $(lpad (elapsed, 9 )) ms " )
866+ printstyled (tree_prefix, color = :light_black )
867+ println (pkg. name)
868+ end
858869 return restored
859870 end
860871 end
0 commit comments