← Back to team overview

touch-packages team mailing list archive

[Bug 1360606] Re: libcairo.so for Ubuntu 14.04 is dead-slow compared to Ubuntu 13.10

 

Hi.

I have tested the example code below on Ubuntu 13.10 and 14.04 desktop
amd64 on several machines such as laptops and Dell dual XEON multi core
with the same trend being very slow on 14.04. I have also asked others
to test the behaviour on various installation and they all report the
same. I would be very surprised if you don't get the same result on your
machine.

Save the code in the file cairotest.c and compile it using this command

  gcc -Wall -L/usr/lib/x86_64-linux-gnu cairotest.c -lcairo -o cairotest

and run it using the command ./cairotest

It clip/paint a scaled image onto a cairo surface although the image is
emulated as a chunk of memory.

If you do not scale, it runs as fast for for both 14.04 and 13.10, but I
suspect it uses memcpy internally.

#include <stdlib.h>
#include <stdio.h>
#include <cairo/cairo.h>
#include <sys/time.h>

int overlay_frame(cairo_t* pCr, u_int8_t* src, int width, int height, double scale_x, double scale_y) {
        double clip_w = width;
        double clip_h = height;
        if (!pCr || !src || !width || !height) return 1;
        cairo_surface_t* pSurface = cairo_image_surface_create_for_data(src,
                CAIRO_FORMAT_ARGB32, width, height, width*4);
        if (!pSurface) {
                fprintf(stderr, "Failed to allocate memory for frame\n");
                return -1;
        }

        cairo_save(pCr);
          if (scale_x != 1.0 || scale_y != 1.0) cairo_scale(pCr, scale_x, scale_y);
            cairo_rectangle(pCr, 0.0, 0.0, clip_w, clip_h);
            cairo_clip(pCr);
            cairo_new_path(pCr);
            cairo_set_source_surface(pCr, pSurface, 0.0, 0.0);
            cairo_paint(pCr);
          if (scale_x != 1.0 || scale_y != 1.0) cairo_scale(pCr, 1/scale_x, 1/scale_y);

          cairo_reset_clip (pCr);
        cairo_restore(pCr);
        if (pSurface) cairo_surface_destroy(pSurface);
        return 0;
}
int main(int argc, char *argv[])
{
        int i = 0;
        int width =1280;
        int height = 720;
        struct timeval start, stop, time;
        u_int8_t* mixerframe = (u_int8_t*)malloc(width*height*4);
        u_int8_t* srcframe = (u_int8_t*)malloc(width*height*4);
        if (!mixerframe || !srcframe) {
                fprintf(stderr, "Failed to allocate memory for frame\n");
                exit (1);
        }
        cairo_surface_t* pSurface = cairo_image_surface_create_for_data(
                mixerframe, CAIRO_FORMAT_ARGB32, width, height, width*4);
        if (!pSurface) {
                fprintf(stderr, "Failed to allocate cairo surface\n");
                exit (1);
        }
        cairo_t* pCr = cairo_create(pSurface);
        if (!pCr) {
                fprintf(stderr, "Failed to allocate cairo context\n");
                exit (1);
        }

        gettimeofday(&start,NULL);
        for (i=0 ; i < 1000; i++) overlay_frame(pCr, srcframe, width, height, 0.5, 0.5);

        gettimeofday(&stop,NULL);
        if (pCr) cairo_destroy(pCr);
        if (pSurface) cairo_surface_destroy(pSurface);
        timersub(&stop,&start,&time);
        fprintf(stdout, "Time spent : %ld.%06ld\n", time.tv_sec, time.tv_usec);
        return 0;
}

-- 
You received this bug notification because you are a member of Ubuntu
Touch seeded packages, which is subscribed to cairo in Ubuntu.
https://bugs.launchpad.net/bugs/1360606

Title:
  libcairo.so for Ubuntu 14.04 is dead-slow compared to Ubuntu 13.10

Status in “cairo” package in Ubuntu:
  New

Bug description:
  I'm running the video mixer software called Snowmix that uses libcairo
  extensively. After updating to Ubuntu 14.04 Desktop amd64, I noticed
  that mixing video required 8 times more CPU compared to Ubuntu 13.10.
  Using oprofile I discovered the heavy CPU load was taking place in
  libpixman used by libcairo. However libpixman is currently the same
  release in Ubuntu 14.04 and 13.10. However I did notice that libcairo
  got upgraded from libcairo.so.2.11200.16 in Ubuntu 13.10 to
  libcairo.so.2.11301.0 in Uuntu 14.04.

  Snowmix uses libcairo2 primarily for scaling and rotating images and
  overlay them in memory.

  Replacing libcairo.so.2.11301.0 with libcairo.so.2.11200.16 in Ubuntu
  14.04 lower the CPU usage by at least 8 times. So I suspect that
  libcairo for Ubuntu 14.04 somehow got compiled without the hardware
  acceleration such as MMX/SSE2/SSE3 etc. This is quite bad if this is
  the case. If it is not the case, something else is seriously wrong
  with libcairo2.

  1)Description:	Ubuntu 14.04.1 LTS
    Release:	14.04
  2) libcairo2:
      Installed: 1.13.0~20140204-0ubuntu1
      Candidate: 1.13.0~20140204-0ubuntu1
      Version table:
     *** 1.13.0~20140204-0ubuntu1 0
          500 http://dk.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages
          100 /var/lib/dpkg/status
  3) I expected libcairo2 (libcairo.so.2.11301.0) for Ubuntu14.04 to work as efficient as libcairo2 (libcairo.so.2.11200.16)for Ubuntu13.10.
  4) Libcairo2 for Ubuntu 14.04 works 8 times slower indicating a lack of MMX/SSE2/SSE3 etc acceleration.

  For the source, you have the source for libcairo2 for Ubuntu14.04.

  I can provide you with the source code for Snowmix using libcairo2,
  but I don't expected you need it nor want it.

  Best regards
  Peter Maersk-Moller

  ProblemType: Bug
  DistroRelease: Ubuntu 14.04
  Package: libcairo2 1.13.0~20140204-0ubuntu1
  ProcVersionSignature: Ubuntu 3.13.0-34.60-generic 3.13.11.4
  Uname: Linux 3.13.0-34-generic x86_64
  ApportVersion: 2.14.1-0ubuntu3.3
  Architecture: amd64
  Date: Sat Aug 23 15:23:38 2014
  InstallationDate: Installed on 2013-06-21 (428 days ago)
  InstallationMedia: Ubuntu 12.04.2 LTS "Precise Pangolin" - Release amd64 (20130213)
  ProcEnviron:
   LANGUAGE=en_US:en
   TERM=xterm
   PATH=(custom, no user)
   LANG=en_US.UTF-8
   SHELL=/bin/bash
  SourcePackage: cairo
  UpgradeStatus: Upgraded to trusty on 2014-08-20 (3 days ago)

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/cairo/+bug/1360606/+subscriptions


References