Re: Creating A Cairo Context Seems Quite Quick

Behdad Esfahbod <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
On 15-04-18 03:30 AM, Lawrence D'Oliveiro wrote:
> I just added methods to my Path and Path.Segment types in Qahirah
> <https://github.com/ldo/qahirah> to compute extents and return
> flattened versions. These create a temporary Cairo context so I can use
> its append_path and copy_path_flat calls to do all the work. The
> overhead of this doesn’t seem too bad.
> 
> As a baseline (on an already-created Cairo context), the Python sequence
> 
>     ctx.new_path().append_path(path).copy_path_flat()
> 
> takes 140µs for a simple rectangular path on my Core i7 (averaged over
> 100,000 iterations using the Python timeit module), while
> 
>     ctx.new_path().append_path(path).path_extents
> 
> takes 59µs. For the new methods I have added, which create a new context
> on every call,
> 
>     path.flatten()
> 
> takes 162µs, while
> 
>     path.extents
> 
> takes 83µs. So the overhead in the former is about 16%, in the latter
> about 40%. Well short of the order-of-magnitude-or-more I was
> expecting/fearing...

Yes, cairo optimizes for that by caching freed context objects for reuse so
there's no malloc() overhead.  All that is left is clearing the object.
-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.