StatProfilerHTML.jl report
Generated on tor 10 okt 2019 11:38:33
File source code
Line Exclusive Inclusive Code
1 # This file is a part of Julia. License is MIT: https://julialang.org/license
2
3 baremodule Base
4
5 using Core.Intrinsics, Core.IR
6
7 const is_primary_base_module = ccall(:jl_module_parent, Ref{Module}, (Any,), Base) === Core.Main
8 ccall(:jl_set_istopmod, Cvoid, (Any, Bool), Base, is_primary_base_module)
9
10 # Try to help prevent users from shooting them-selves in the foot
11 # with ambiguities by defining a few common and critical operations
12 # (and these don't need the extra convert code)
13 getproperty(x::Module, f::Symbol) = getfield(x, f)
14 setproperty!(x::Module, f::Symbol, v) = setfield!(x, f, v)
15 getproperty(x::Type, f::Symbol) = getfield(x, f)
16 setproperty!(x::Type, f::Symbol, v) = setfield!(x, f, v)
17
18 getproperty(Core.@nospecialize(x), f::Symbol) = getfield(x, f)
19 setproperty!(x, f::Symbol, v) = setfield!(x, f, convert(fieldtype(typeof(x), f), v))
20
21 function include_relative end
22
40 (95.24%) samples spent in include
0 (ex.), 40 (100.00%) (incl.) when called from exec_options line 266
function include(mod::Module, path::AbstractString)
23 local result
24 if INCLUDE_STATE === 1
25 result = _include1(mod, path)
26 elseif INCLUDE_STATE === 2
27 result = _include(mod, path)
28 elseif INCLUDE_STATE === 3
29 40 (95.24%)
40 (100.00%) samples spent calling include_relative
result = include_relative(mod, path)
30 end
31 result
32 end
33 function include(path::AbstractString)
34 local result
35 if INCLUDE_STATE === 1
36 result = _include1(Base, path)
37 elseif INCLUDE_STATE === 2
38 result = _include(Base, path)
39 else
40 # to help users avoid error (accidentally evaluating into Base), this is not allowed
41 error("Base.include(string) is discontinued, use `include(fname)` or `Base.include(@__MODULE__, fname)` instead.")
42 end
43 result
44 end
45 const _included_files = Array{Tuple{Module,String},1}()
46 function _include1(mod::Module, path)
47 Core.Compiler.push!(_included_files, (mod, ccall(:jl_prepend_cwd, Any, (Any,), path)))
48 Core.include(mod, path)
49 end
50 let SOURCE_PATH = ""
51 # simple, race-y TLS, relative include
52 global _include
53 function _include(mod::Module, path)
54 prev = SOURCE_PATH
55 path = normpath(joinpath(dirname(prev), path))
56 push!(_included_files, (mod, abspath(path)))
57 SOURCE_PATH = path
58 result = Core.include(mod, path)
59 SOURCE_PATH = prev
60 result
61 end
62 end
63 INCLUDE_STATE = 1 # include = Core.include
64
65 include("coreio.jl")
66
67 eval(x) = Core.eval(Base, x)
68 eval(m::Module, x) = Core.eval(m, x)
69
70 VecElement{T}(arg) where {T} = VecElement{T}(convert(T, arg))
71 convert(::Type{T}, arg) where {T<:VecElement} = T(arg)
72 convert(::Type{T}, arg::T) where {T<:VecElement} = arg
73
74 # init core docsystem
75 import Core: @doc, @__doc__, WrappedException
76 if isdefined(Core, :Compiler)
77 import Core.Compiler.CoreDocs
78 Core.atdoc!(CoreDocs.docm)
79 end
80
81 include("exports.jl")
82
83 if false
84 # simple print definitions for debugging. enable these if something
85 # goes wrong during bootstrap before printing code is available.
86 # otherwise, they just just eventually get (noisily) overwritten later
87 global show, print, println
88 show(io::IO, x) = Core.show(io, x)
89 print(io::IO, a...) = Core.print(io, a...)
90 println(io::IO, x...) = Core.println(io, x...)
91 end
92
93 """
94 time_ns()
95
96 Get the time in nanoseconds. The time corresponding to 0 is undefined, and wraps every 5.8 years.
97 """
98 time_ns() = ccall(:jl_hrtime, UInt64, ())
99
100 start_base_include = time_ns()
101
102 ## Load essential files and libraries
103 include("essentials.jl")
104 include("ctypes.jl")
105 include("gcutils.jl")
106 include("generator.jl")
107 include("reflection.jl")
108 include("options.jl")
109
110 # core operations & types
111 include("promotion.jl")
112 include("tuple.jl")
113 include("pair.jl")
114 include("traits.jl")
115 include("range.jl")
116 include("expr.jl")
117 include("error.jl")
118
119 # core numeric operations & types
120 include("bool.jl")
121 include("number.jl")
122 include("int.jl")
123 include("operators.jl")
124 include("pointer.jl")
125 include("refvalue.jl")
126 include("refpointer.jl")
127 include("checked.jl")
128 using .Checked
129
130 # vararg Symbol constructor
131 Symbol(x...) = Symbol(string(x...))
132
133 # array structures
134 include("indices.jl")
135 include("array.jl")
136 include("abstractarray.jl")
137 include("subarray.jl")
138 include("views.jl")
139
140 # ## dims-type-converting Array constructors for convenience
141 # type and dimensionality specified, accepting dims as series of Integers
142 Vector{T}(::UndefInitializer, m::Integer) where {T} = Vector{T}(undef, Int(m))
143 Matrix{T}(::UndefInitializer, m::Integer, n::Integer) where {T} = Matrix{T}(undef, Int(m), Int(n))
144 Array{T,N}(::UndefInitializer, d::Vararg{Integer,N}) where {T,N} = Array{T,N}(undef, convert(Tuple{Vararg{Int}}, d))
145 # type but not dimensionality specified, accepting dims as series of Integers
146 Array{T}(::UndefInitializer, m::Integer) where {T} = Array{T,1}(undef, Int(m))
147 Array{T}(::UndefInitializer, m::Integer, n::Integer) where {T} = Array{T,2}(undef, Int(m), Int(n))
148 Array{T}(::UndefInitializer, m::Integer, n::Integer, o::Integer) where {T} = Array{T,3}(undef, Int(m), Int(n), Int(o))
149 Array{T}(::UndefInitializer, d::Integer...) where {T} = Array{T}(undef, convert(Tuple{Vararg{Int}}, d))
150 # dimensionality but not type specified, accepting dims as series of Integers
151 Vector(::UndefInitializer, m::Integer) = Vector{Any}(undef, Int(m))
152 Matrix(::UndefInitializer, m::Integer, n::Integer) = Matrix{Any}(undef, Int(m), Int(n))
153 # Dimensions as a single tuple
154 Array{T}(::UndefInitializer, d::NTuple{N,Integer}) where {T,N} = Array{T,N}(undef, convert(Tuple{Vararg{Int}}, d))
155 Array{T,N}(::UndefInitializer, d::NTuple{N,Integer}) where {T,N} = Array{T,N}(undef, convert(Tuple{Vararg{Int}}, d))
156 # empty vector constructor
157 Vector() = Vector{Any}(undef, 0)
158
159 # Array constructors for nothing and missing
160 # type and dimensionality specified
161 Array{T,N}(::Nothing, d...) where {T,N} = fill!(Array{T,N}(undef, d...), nothing)
162 Array{T,N}(::Missing, d...) where {T,N} = fill!(Array{T,N}(undef, d...), missing)
163 # type but not dimensionality specified
164 Array{T}(::Nothing, d...) where {T} = fill!(Array{T}(undef, d...), nothing)
165 Array{T}(::Missing, d...) where {T} = fill!(Array{T}(undef, d...), missing)
166
167 include("abstractdict.jl")
168
169 include("iterators.jl")
170 using .Iterators: zip, enumerate
171 using .Iterators: Flatten, product # for generators
172
173 include("namedtuple.jl")
174
175 # numeric operations
176 include("hashing.jl")
177 include("rounding.jl")
178 using .Rounding
179 include("float.jl")
180 include("twiceprecision.jl")
181 include("complex.jl")
182 include("rational.jl")
183 include("multinverses.jl")
184 using .MultiplicativeInverses
185 include("abstractarraymath.jl")
186 include("arraymath.jl")
187
188 # define MIME"foo/bar" early so that we can overload 3-arg show
189 struct MIME{mime} end
190 macro MIME_str(s)
191 :(MIME{$(Expr(:quote, Symbol(s)))})
192 end
193 # fallback text/plain representation of any type:
194 show(io::IO, ::MIME"text/plain", x) = show(io, x)
195
196 # SIMD loops
197 include("simdloop.jl")
198 using .SimdLoop
199
200 # map-reduce operators
201 include("reduce.jl")
202
203 ## core structures
204 include("reshapedarray.jl")
205 include("reinterpretarray.jl")
206 include("bitarray.jl")
207 include("bitset.jl")
208
209 if !isdefined(Core, :Compiler)
210 include("docs/core.jl")
211 Core.atdoc!(CoreDocs.docm)
212 end
213
214 # Some type
215 include("some.jl")
216
217 include("dict.jl")
218 include("abstractset.jl")
219 include("set.jl")
220
221 include("char.jl")
222 include("strings/basic.jl")
223 include("strings/string.jl")
224 include("strings/substring.jl")
225
226 # Definition of StridedArray
227 StridedFastContiguousSubArray{T,N,A<:DenseArray} = FastContiguousSubArray{T,N,A}
228 StridedReinterpretArray{T,N,A<:Union{DenseArray,StridedFastContiguousSubArray}} = ReinterpretArray{T,N,S,A} where S
229 StridedReshapedArray{T,N,A<:Union{DenseArray,StridedFastContiguousSubArray,StridedReinterpretArray}} = ReshapedArray{T,N,A}
230 StridedSubArray{T,N,A<:Union{DenseArray,StridedReshapedArray,StridedReinterpretArray},
231 I<:Tuple{Vararg{Union{RangeIndex, AbstractCartesianIndex}}}} = SubArray{T,N,A,I}
232 StridedArray{T,N} = Union{DenseArray{T,N}, StridedSubArray{T,N}, StridedReshapedArray{T,N}, StridedReinterpretArray{T,N}}
233 StridedVector{T} = Union{DenseArray{T,1}, StridedSubArray{T,1}, StridedReshapedArray{T,1}, StridedReinterpretArray{T,1}}
234 StridedMatrix{T} = Union{DenseArray{T,2}, StridedSubArray{T,2}, StridedReshapedArray{T,2}, StridedReinterpretArray{T,2}}
235 StridedVecOrMat{T} = Union{StridedVector{T}, StridedMatrix{T}}
236
237 # For OS specific stuff
238 include(string((length(Core.ARGS)>=2 ? Core.ARGS[2] : ""), "build_h.jl")) # include($BUILDROOT/base/build_h.jl)
239 include(string((length(Core.ARGS)>=2 ? Core.ARGS[2] : ""), "version_git.jl")) # include($BUILDROOT/base/version_git.jl)
240
241 include("osutils.jl")
242 include("c.jl")
243
244 # Core I/O
245 include("io.jl")
246 include("iostream.jl")
247 include("iobuffer.jl")
248
249 # strings & printing
250 include("intfuncs.jl")
251 include("strings/strings.jl")
252 include("parse.jl")
253 include("shell.jl")
254 include("regex.jl")
255 include("show.jl")
256 include("arrayshow.jl")
257
258 # multidimensional arrays
259 include("cartesian.jl")
260 using .Cartesian
261 include("multidimensional.jl")
262 include("permuteddimsarray.jl")
263 using .PermutedDimsArrays
264
265 include("broadcast.jl")
266 using .Broadcast
267
268 # define the real ntuple functions
269 @inline function ntuple(f::F, ::Val{N}) where {F,N}
270 N::Int
271 (N >= 0) || throw(ArgumentError(string("tuple length should be ≥0, got ", N)))
272 if @generated
273 quote
274 @nexprs $N i -> t_i = f(i)
275 @ncall $N tuple t
276 end
277 else
278 Tuple(f(i) for i = 1:N)
279 end
280 end
281 @inline function fill_to_length(t::Tuple, val, ::Val{N}) where {N}
282 M = length(t)
283 M > N && throw(ArgumentError("input tuple of length $M, requested $N"))
284 if @generated
285 quote
286 (t..., $(fill(:val, N-length(t.parameters))...))
287 end
288 else
289 (t..., fill(val, N-M)...)
290 end
291 end
292
293 # missing values
294 include("missing.jl")
295
296 # version
297 include("version.jl")
298
299 # system & environment
300 include("sysinfo.jl")
301 include("libc.jl")
302 using .Libc: getpid, gethostname, time
303
304 const DL_LOAD_PATH = String[]
305 if Sys.isapple()
306 push!(DL_LOAD_PATH, "@loader_path/julia")
307 push!(DL_LOAD_PATH, "@loader_path")
308 end
309
310 include("env.jl")
311
312 # Scheduling
313 include("libuv.jl")
314 include("event.jl")
315 include("task.jl")
316 include("lock.jl")
317 include("threads.jl")
318 include("weakkeydict.jl")
319
320 # Logging
321 include("logging.jl")
322 using .CoreLogging
323
324 # functions defined in Random
325 function rand end
326 function randn end
327
328 # I/O
329 include("stream.jl")
330 include("filesystem.jl")
331 using .Filesystem
332 include("process.jl")
333 include("grisu/grisu.jl")
334 include("methodshow.jl")
335 include("secretbuffer.jl")
336
337 # core math functions
338 include("floatfuncs.jl")
339 include("math.jl")
340 using .Math
341 const (√)=sqrt
342 const (∛)=cbrt
343
344 INCLUDE_STATE = 2 # include = _include (from lines above)
345
346 # reduction along dims
347 include("reducedim.jl") # macros in this file relies on string.jl
348 include("accumulate.jl")
349
350 # basic data structures
351 include("ordering.jl")
352 using .Order
353
354 # Combinatorics
355 include("sort.jl")
356 using .Sort
357
358 # Fast math
359 include("fastmath.jl")
360 using .FastMath
361
362 function deepcopy_internal end
363
364 # BigInts and BigFloats
365 include("gmp.jl")
366 using .GMP
367
368 for T in [Signed, Integer, BigInt, Float32, Float64, Real, Complex, Rational]
369 @eval flipsign(x::$T, ::Unsigned) = +x
370 @eval copysign(x::$T, ::Unsigned) = +x
371 end
372
373 include("mpfr.jl")
374 using .MPFR
375 big(n::Integer) = convert(BigInt,n)
376 big(x::AbstractFloat) = convert(BigFloat,x)
377 big(q::Rational) = big(numerator(q))//big(denominator(q))
378
379 include("combinatorics.jl")
380
381 # more hashing definitions
382 include("hashing2.jl")
383
384 # irrational mathematical constants
385 include("irrationals.jl")
386 include("mathconstants.jl")
387 using .MathConstants: ℯ, π, pi
388
389 # (s)printf macros
390 include("printf.jl")
391 # import .Printf
392
393 # metaprogramming
394 include("meta.jl")
395
396 # enums
397 include("Enums.jl")
398 using .Enums
399
400 # concurrency and parallelism
401 include("channels.jl")
402
403 # utilities
404 include("deepcopy.jl")
405 include("download.jl")
406 include("summarysize.jl")
407 include("errorshow.jl")
408
409 # Stack frames and traces
410 include("stacktraces.jl")
411 using .StackTraces
412
413 include("initdefs.jl")
414
415 # worker threads
416 include("threadcall.jl")
417
418 # code loading
419 include("uuid.jl")
420 include("loading.jl")
421
422 # misc useful functions & macros
423 include("util.jl")
424
425 include("asyncmap.jl")
426
427 include("multimedia.jl")
428 using .Multimedia
429
430 # deprecated functions
431 include("deprecated.jl")
432
433 # Some basic documentation
434 include("docs/basedocs.jl")
435
436 include("client.jl")
437
438 # Documentation -- should always be included last in sysimg.
439 include("docs/Docs.jl")
440 using .Docs
441 if isdefined(Core, :Compiler) && is_primary_base_module
442 Docs.loaddocs(Core.Compiler.CoreDocs.DOCS)
443 end
444
445 end_base_include = time_ns()
446
447 if is_primary_base_module
448 function __init__()
449 # try to ensuremake sure OpenBLAS does not set CPU affinity (#1070, #9639)
450 if !haskey(ENV, "OPENBLAS_MAIN_FREE") && !haskey(ENV, "GOTOBLAS_MAIN_FREE")
451 ENV["OPENBLAS_MAIN_FREE"] = "1"
452 end
453 # And try to prevent openblas from starting too many threads, unless/until specifically requested
454 if !haskey(ENV, "OPENBLAS_NUM_THREADS") && !haskey(ENV, "OMP_NUM_THREADS")
455 cpu_threads = Sys.CPU_THREADS::Int
456 if cpu_threads > 8 # always at most 8
457 ENV["OPENBLAS_NUM_THREADS"] = "8"
458 elseif haskey(ENV, "JULIA_CPU_THREADS") # or exactly as specified
459 ENV["OPENBLAS_NUM_THREADS"] = cpu_threads
460 end # otherwise, trust that openblas will pick CPU_THREADS anyways, without any intervention
461 end
462 # for the few uses of Libc.rand in Base:
463 Libc.srand()
464 # Base library init
465 reinit_stdio()
466 Multimedia.reinit_displays() # since Multimedia.displays uses stdout as fallback
467 # initialize loading
468 init_depot_path()
469 init_load_path()
470 nothing
471 end
472
473 INCLUDE_STATE = 3 # include = include_relative
474 end
475
476 const tot_time_stdlib = RefValue(0.0)
477
478 end # baremodule Base
479
480 using .Base
481
482 # Ensure this file is also tracked
483 pushfirst!(Base._included_files, (@__MODULE__, joinpath(@__DIR__, "sysimg.jl")))
484
485 # set up depot & load paths to be able to find stdlib packages
486 @eval Base creating_sysimg = true
487 Base.init_depot_path()
488 Base.init_load_path()
489
490 if Base.is_primary_base_module
491 # load some stdlib packages but don't put their names in Main
492 let
493 # Stdlibs manually sorted in top down order
494 stdlibs = [
495 # No deps
496 :Base64,
497 :CRC32c,
498 :SHA,
499 :FileWatching,
500 :Unicode,
501 :Mmap,
502 :Serialization,
503 :Libdl,
504 :Markdown,
505 :LibGit2,
506 :Logging,
507 :Sockets,
508 :Printf,
509 :Profile,
510 :Dates,
511 :DelimitedFiles,
512 :Random,
513 :UUIDs,
514 :Future,
515 :LinearAlgebra,
516 :SparseArrays,
517 :SuiteSparse,
518 :Distributed,
519 :SharedArrays,
520 :Pkg,
521 :Test,
522 :REPL,
523 :Statistics,
524 ]
525
526 maxlen = maximum(textwidth.(string.(stdlibs)))
527
528 print_time = (mod, t) -> (print(rpad(string(mod) * " ", maxlen + 3, "─")); Base.time_print(t * 10^9); println())
529 print_time(Base, (Base.end_base_include - Base.start_base_include) * 10^(-9))
530
531 Base._track_dependencies[] = true
532 Base.tot_time_stdlib[] = @elapsed for stdlib in stdlibs
533 tt = @elapsed Base.require(Base, stdlib)
534 print_time(stdlib, tt)
535 end
536 for dep in Base._require_dependencies
537 dep[3] == 0.0 && continue
538 push!(Base._included_files, dep[1:2])
539 end
540 empty!(Base._require_dependencies)
541 Base._track_dependencies[] = false
542
543 print_time("Stdlibs total", Base.tot_time_stdlib[])
544 end
545 end
546
547 # Clear global state
548 empty!(Core.ARGS)
549 empty!(Base.ARGS)
550 empty!(LOAD_PATH)
551 @eval Base creating_sysimg = false
552 Base.init_load_path() # want to be able to find external packages in userimg.jl
553
554 let
555 tot_time_userimg = @elapsed (Base.isfile("userimg.jl") && Base.include(Main, "userimg.jl"))
556
557
558 tot_time_base = (Base.end_base_include - Base.start_base_include) * 10.0^(-9)
559 tot_time = tot_time_base + Base.tot_time_stdlib[] + tot_time_userimg
560
561 println("Sysimage built. Summary:")
562 print("Total ─────── "); Base.time_print(tot_time * 10^9); print(" \n");
563 print("Base: ─────── "); Base.time_print(tot_time_base * 10^9); print(" "); show(IOContext(stdout, :compact=>true), (tot_time_base / tot_time) * 100); println("%")
564 print("Stdlibs: ──── "); Base.time_print(Base.tot_time_stdlib[] * 10^9); print(" "); show(IOContext(stdout, :compact=>true), (Base.tot_time_stdlib[] / tot_time) * 100); println("%")
565 if isfile("userimg.jl")
566 print("Userimg: ──── "); Base.time_print(tot_time_userimg * 10^9); print(" "); show(IOContext(stdout, :compact=>true), (tot_time_userimg / tot_time) * 100); println("%")
567 end
568 end
569
570 empty!(LOAD_PATH)
571 empty!(DEPOT_PATH)