Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 63473557 authored by Vincent Liard's avatar Vincent Liard
Browse files

fix slow X on OSX since Yosemite update

The OSX Yosemite (10.10) update came with a dramatic
slowdown in aevol X displays. The problem comes from
slow calls to Xlib's XAllocColor() in
ae_X11_window::get_pixel(...).

Since debugging the problem would require to trace
the program down to the Xlib, it has been solved
with a workaround by memoizing the calls to get_pixel()
so that XAllocColor() be actually called only when
requiring a new color.

This solutions costs a bit or memory (around 20Kb on
the basic example) but the display's colors are
preserved and the speed is back to decent.
parent 81db6130
No related branches found
No related tags found
No related merge requests found
......@@ -35,9 +35,8 @@
#include <string>
#include <X11/Xutil.h>
#include <X11/cursorfont.h>
#include <unordered_map>
#include <string>
// =================================================================
// Project Files
......@@ -46,9 +45,6 @@
#include <ae_exp_setup.h>
// =================================================================
// Basic X11/Xlib notions
// =================================================================
......@@ -533,26 +529,26 @@ char* ae_X11_window::get_color( double mean )
// Protected Methods
// =================================================================
uint32_t ae_X11_window::get_pixel( Display *display, int8_t screen, char *color_name, uint32_t default_color )
uint32_t ae_X11_window::get_pixel(Display *display, int8_t screen, char *color_name, uint32_t default_color)
{
XColor color;
if ( XParseColor( display, DefaultColormap(display,screen), color_name, &color ) == 0 )
{
fprintf( stderr, "Invalid colour : %s\n", color_name );
return default_color;
// hacked on 2014-12-05 because XQuarz and Yosemite make XAllocColor veeery slow
// dirty memoization workaround: display and screen are assumed to be constant
// costs 21Kb of RAM on basic example (according to the measure given before the return)
static std::unordered_map <std::string, unsigned long> color_memo;
// if color_name is already recorded, compute and record it
if (color_memo.find(color_name) == color_memo.end()) {
XColor color;
if (XParseColor(display, DefaultColormap(display,screen), color_name, &color) == 0) {
fprintf(stderr, "Invalid color: %s\n", color_name);
return default_color;
}
if (XAllocColor(display, DefaultColormap(display,screen), &color) == 0) {
fprintf(stderr, "Could not allocate color %s\n", color_name);
return default_color;
}
color_memo[color_name] = color.pixel;
}
if ( XAllocColor( display, DefaultColormap(display,screen), &color ) == 0 )
{
fprintf( stderr, "Could not allocate colour %s\n", color_name );
return default_color;
}
return color.pixel;
// printf("ram used: %lu bytes\n", sizeof(color_memo) + color_memo.size() * (sizeof(std::string) + sizeof(unsigned long)));
return color_memo[color_name];
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment