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

CairoContext() is much slower than it used to be (macOS) #270

Closed
cormullion opened this issue Jan 16, 2019 · 6 comments
Closed

CairoContext() is much slower than it used to be (macOS) #270

cormullion opened this issue Jan 16, 2019 · 6 comments

Comments

@cormullion
Copy link
Member

This is more of an question than an issue, but I've been gradually coming to the conclusion that Cairo now takes much longer to "start up" (create a context) than it used to.

Here's an example on Julia version 0.6, running on a 10 year old computer:

               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.6.0 (2017-06-19 13:05 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
|__/                   |  x86_64-apple-darwin13.4.0

julia> using Cairo

julia> @time cr = CairoRGBSurface(256, 256)
  0.015400 seconds (3.11 k allocations: 185.470 KiB)
Cairo.CairoSurface{UInt32}(Ptr{Void} @0x00007fee8c513930, 256.0, 256.0, #undef)

julia> @time c = CairoContext(cr)
  0.370006 seconds (2.55 k allocations: 142.626 KiB)
Cairo.CairoContext(Ptr{Void} @0x00007fee8b463600, Cairo.CairoSurface{UInt32}(Ptr{Void} @0x00007fee8c513930, 256.0, 256.0, #undef), Ptr{Void} @0x00007fee8b60f800)

and here's the time on Julia v1.0 for the same code.

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.0.2 (2018-11-08)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia-1.0> using Cairo

julia-1.0> @time cr = CairoRGBSurface(256, 256)
  0.104971 seconds (21.46 k allocations: 1.073 MiB)
Cairo.CairoSurfaceBase{UInt32}(Ptr{Nothing} @0x00007fdde2819aa0, 256.0, 256.0)

julia-1.0> @time c = CairoContext(cr)
 11.136036 seconds (9.58 k allocations: 534.713 KiB)
CairoContext(Ptr{Nothing} @0x00007fdde0844200, Cairo.CairoSurfaceBase{UInt32}(Ptr{Nothing} @0x00007fdde2819aa0, 256.0, 256.0), Ptr{Nothing} @0x00007fdde124e000)

That's 30 times slower on the computer that's probably 30 times faster. (I can't run Julia v1.0 on the old computer anymore, it's that old.)

So I'm wondering whether there's an obvious reason for the slowdown, and how to investigate the issue further.

@lobingera
Copy link
Contributor

Here:

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.0.2 (2018-11-08)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using Cairo

julia> @time cr = CairoRGBSurface(256, 256)
  0.013114 seconds (21.46 k allocations: 1.073 MiB)
Cairo.CairoSurfaceBase{UInt32}(Ptr{Nothing} @0x0000000002c7ba60, 256.0, 256.0)

julia> @time c = CairoContext(cr)
  0.013396 seconds (9.58 k allocations: 534.775 KiB)
CairoContext(Ptr{Nothing} @0x0000000002d8c030, Cairo.CairoSurfaceBase{UInt32}(Ptr{Nothing} @0x0000000002c7ba60, 256.0, 256.0), Ptr{Nothing} @0x0000000002e12810)

@cormullion
Copy link
Member Author

cormullion commented Jan 16, 2019

Blimey. Is that v0.5.6 on Linux? (I'm on v0.5.6 on macOS.)

@lobingera
Copy link
Contributor

yes, that's linux and [159f3aea] Cairo v0.5.6+ [~/.julia/dev/Cairo]

@cormullion
Copy link
Member Author

I'll ask for a few more data points...

@cormullion
Copy link
Member Author

My current theory is that the number of fonts that are installed and active affects the start-up time for contexts. Some data points:

User Platform Julia Cairo Time1 Time2
cormullion macOS v0.6 v0.3.1 0.0154 0.370006
cormullion macOS v1.0.2 v0.5.6 0.104971 11.136036
cormullion macOS v1.1.0 v0.5.6 0.008384 10.546599
lobingera Linux v1.0.2 v0.5.6 0.013114 0.013396
pfitzseb Linux v1.0.3 v0.5.6 0.010506 0.00527
tobias.knopp macOS v1.1 v0.5.6 0.011026 0.570303
mkborregaard macOS v1.1 v0.5.6 0.285513 1.812419
goedman macOS v1.1 v0.5.6 0.00978 0.397401

The longer times here seem to be because these users have 'more than a few' fonts installed and active.

Probably no point in keeping this open!

@lobingera
Copy link
Contributor

The cairocontext of an existing surface is internally more or less a copy of a pointer. The designers of Cairo.jl decided to add a pango layout here - which is needed if you want to use pango for text setting. So it might make sense to actually profile the full call to see if the time is spend in the first part (get contect) or second (create layout).

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

No branches or pull requests

2 participants