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

Add some precompiles #370

Merged
merged 2 commits into from
Dec 12, 2019
Merged

Add some precompiles #370

merged 2 commits into from
Dec 12, 2019

Conversation

timholy
Copy link
Member

@timholy timholy commented Dec 3, 2019

This adds some precompile statements to reduce latency. Because the methods are simple to infer, the savings are modest, but combined with precompiles in other packages (FixedPointNumbers, ColorTypes, ColorVectorSpace) I'm getting latency reductions of ~30% for some common operations. So these seem worth having.

@johnnychen94
Copy link
Member

Would you mind to kindly point out where related documentation can be found? This topic looks interesting

@timholy
Copy link
Member Author

timholy commented Dec 3, 2019

https://github.com/timholy/SnoopCompile.jl

@kimikage
Copy link
Collaborator

kimikage commented Dec 5, 2019

Does precompiling have side effects?

julia> versioninfo()
Julia Version 1.3.0
Commit 46ce4d7933 (2019-11-26 06:09 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)

master

julia> @time parse(RGB{Float32}, "#C0FFEE")
  0.233481 seconds (981.38 k allocations: 50.342 MiB, 4.99% gc time)
RGB{Float32}(0.7529412f0,1.0f0,0.93333334f0)

julia> @time parse(RGB{Float32}, "#C0FFEE")
  0.000017 seconds (13 allocations: 576 bytes)
RGB{Float32}(0.7529412f0,1.0f0,0.93333334f0)

julia> @time parse(Colorant, "#C0FFEE")
  0.001666 seconds (1.94 k allocations: 116.674 KiB)
RGB{N0f8}(0.753,1.0,0.933)

julia> @time parse(Colorant, "#C0FFEE")
  0.000010 seconds (11 allocations: 512 bytes)
RGB{N0f8}(0.753,1.0,0.933)

teh/precompile

julia> @time parse(RGB{Float32}, "#C0FFEE")
  0.098095 seconds (115.82 k allocations: 6.166 MiB)
RGB{Float32}(0.7529412f0,1.0f0,0.93333334f0)

julia> @time parse(RGB{Float32}, "#C0FFEE")
  0.000014 seconds (14 allocations: 592 bytes)
RGB{Float32}(0.7529412f0,1.0f0,0.93333334f0)

julia> @time parse(Colorant, "#C0FFEE")
  0.001681 seconds (1.94 k allocations: 116.439 KiB)
RGB{N0f8}(0.753,1.0,0.933)

julia> @time parse(Colorant, "#C0FFEE")
  0.000010 seconds (12 allocations: 528 bytes)
RGB{N0f8}(0.753,1.0,0.933)

Edit:
In this case, the difference is whether RGBA() is inlined or not. (Not again!)
I don't understand why this happens.

(This is a off-topic, but I should have added @inbounds for mat.captures[*]. I will do it when implementing the 4-digit/8-digit hex notation parser.)

@codecov
Copy link

codecov bot commented Dec 6, 2019

Codecov Report

Merging #370 into master will increase coverage by 0.25%.
The diff coverage is 90%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #370      +/-   ##
==========================================
+ Coverage   76.98%   77.24%   +0.25%     
==========================================
  Files          10       11       +1     
  Lines         817      835      +18     
==========================================
+ Hits          629      645      +16     
- Misses        188      190       +2
Impacted Files Coverage Δ
src/Colors.jl 100% <ø> (ø) ⬆️
src/utilities.jl 94.73% <100%> (ø) ⬆️
src/precompile.jl 88.88% <88.88%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1bc194e...eb734ea. Read the comment docs.

@kimikage
Copy link
Collaborator

kimikage commented Dec 8, 2019

master

julia> using Colors

julia> precompile(Tuple{typeof(parse),Type{ColorTypes.Colorant},String})
true

julia> @time parse(Colorant, "#C0FFEE")
  0.000055 seconds (12 allocations: 560 bytes)
RGB{N0f8}(0.753,1.0,0.933)

julia> @time parse(Colorant, "#C0FFEE")
  0.000008 seconds (11 allocations: 512 bytes)
RGB{N0f8}(0.753,1.0,0.933)

What's going on here?

Edit:
If there is a negative impact on performance, let's report the issue in each package and then merge.
JuliaMath/FixedPointNumbers.jl#148
JuliaGraphics/ColorTypes.jl#136
JuliaGraphics/ColorVectorSpace.jl#110

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.

3 participants