From 6714d6fc820e56ea53cd67e604a0928e7a974e84 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sat, 10 Aug 2013 17:18:12 +0200 Subject: [PATCH] core: optimize the removal of lines in buffers (a lot faster to clear/close buffers with lot of lines) The update of variables "buffer_max_length" and "prefix_max_length" in struct t_gui_lines is now delayed and made during the main refresh (in main loop). For a buffer with 50K lines, it is up to 3300 times faster to clear/close it. For a buffer with 4096 lines (default limit), it is up to 120 times faster. --- ChangeLog | 2 ++ doc/de/autogen/plugin_api/hdata.txt | 4 ++- doc/en/autogen/plugin_api/hdata.txt | 4 ++- doc/fr/autogen/plugin_api/hdata.txt | 4 ++- doc/it/autogen/plugin_api/hdata.txt | 4 ++- doc/ja/autogen/plugin_api/hdata.txt | 4 ++- src/core/wee-config.c | 4 +-- src/gui/curses/gui-curses-main.c | 30 ++++++++++++++++++ src/gui/gui-buffer.c | 7 ++--- src/gui/gui-filter.c | 2 +- src/gui/gui-line.c | 47 ++++++++++++++++------------- src/gui/gui-line.h | 2 ++ 12 files changed, 81 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index 551a2f849..50f5dd82c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,8 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] Version 0.4.2 (under dev!) -------------------------- +* core: optimize the removal of lines in buffers (a lot faster to clear/close + buffers with lot of lines) * core: change color format for options weechat.look.buffer_time_format and weechat.look.prefix_{action|error|join|network|quit} from `${xxx}` to `${color:xxx}` diff --git a/doc/de/autogen/plugin_api/hdata.txt b/doc/de/autogen/plugin_api/hdata.txt index f5c6ff80e..863a575d9 100644 --- a/doc/de/autogen/plugin_api/hdata.txt +++ b/doc/de/autogen/plugin_api/hdata.txt @@ -786,7 +786,9 @@ 'first_line_not_read' (integer) + 'lines_hidden' (integer) + 'buffer_max_length' (integer) + - 'prefix_max_length' (integer) | + 'buffer_max_length_refresh' (integer) + + 'prefix_max_length' (integer) + + 'prefix_max_length_refresh' (integer) | | - diff --git a/doc/en/autogen/plugin_api/hdata.txt b/doc/en/autogen/plugin_api/hdata.txt index e795d0732..a7ad11646 100644 --- a/doc/en/autogen/plugin_api/hdata.txt +++ b/doc/en/autogen/plugin_api/hdata.txt @@ -786,7 +786,9 @@ 'first_line_not_read' (integer) + 'lines_hidden' (integer) + 'buffer_max_length' (integer) + - 'prefix_max_length' (integer) | + 'buffer_max_length_refresh' (integer) + + 'prefix_max_length' (integer) + + 'prefix_max_length_refresh' (integer) | | - diff --git a/doc/fr/autogen/plugin_api/hdata.txt b/doc/fr/autogen/plugin_api/hdata.txt index d24815bcc..260c6cc1e 100644 --- a/doc/fr/autogen/plugin_api/hdata.txt +++ b/doc/fr/autogen/plugin_api/hdata.txt @@ -786,7 +786,9 @@ 'first_line_not_read' (integer) + 'lines_hidden' (integer) + 'buffer_max_length' (integer) + - 'prefix_max_length' (integer) | + 'buffer_max_length_refresh' (integer) + + 'prefix_max_length' (integer) + + 'prefix_max_length_refresh' (integer) | | - diff --git a/doc/it/autogen/plugin_api/hdata.txt b/doc/it/autogen/plugin_api/hdata.txt index cadd47187..1ff5ae4e7 100644 --- a/doc/it/autogen/plugin_api/hdata.txt +++ b/doc/it/autogen/plugin_api/hdata.txt @@ -786,7 +786,9 @@ 'first_line_not_read' (integer) + 'lines_hidden' (integer) + 'buffer_max_length' (integer) + - 'prefix_max_length' (integer) | + 'buffer_max_length_refresh' (integer) + + 'prefix_max_length' (integer) + + 'prefix_max_length_refresh' (integer) | | - diff --git a/doc/ja/autogen/plugin_api/hdata.txt b/doc/ja/autogen/plugin_api/hdata.txt index 104c3bd93..5f1dfe12f 100644 --- a/doc/ja/autogen/plugin_api/hdata.txt +++ b/doc/ja/autogen/plugin_api/hdata.txt @@ -786,7 +786,9 @@ 'first_line_not_read' (integer) + 'lines_hidden' (integer) + 'buffer_max_length' (integer) + - 'prefix_max_length' (integer) | + 'buffer_max_length_refresh' (integer) + + 'prefix_max_length' (integer) + + 'prefix_max_length_refresh' (integer) | | - diff --git a/src/core/wee-config.c b/src/core/wee-config.c index a7218a0dd..e536d3a0f 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -412,9 +412,9 @@ config_compute_prefix_max_length_all_buffers () ptr_buffer = ptr_buffer->next_buffer) { if (ptr_buffer->own_lines) - gui_line_compute_prefix_max_length (ptr_buffer->own_lines); + ptr_buffer->own_lines->prefix_max_length_refresh = 1; if (ptr_buffer->mixed_lines) - gui_line_compute_prefix_max_length (ptr_buffer->mixed_lines); + ptr_buffer->mixed_lines->prefix_max_length_refresh = 1; } } diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c index 0cc13acee..5377d88eb 100644 --- a/src/gui/curses/gui-curses-main.c +++ b/src/gui/curses/gui-curses-main.c @@ -51,6 +51,7 @@ #include "../gui-filter.h" #include "../gui-input.h" #include "../gui-layout.h" +#include "../gui-line.h" #include "../gui-history.h" #include "../gui-mouse.h" #include "../gui-nicklist.h" @@ -311,6 +312,35 @@ gui_main_refreshs () gui_color_buffer_refresh_needed = 0; } + /* compute max length for prefix/buffer if needed */ + for (ptr_buffer = gui_buffers; ptr_buffer; + ptr_buffer = ptr_buffer->next_buffer) + { + /* compute buffer/prefix max length for own_lines */ + if (ptr_buffer->own_lines) + { + if (ptr_buffer->own_lines->buffer_max_length_refresh) + { + gui_line_compute_buffer_max_length (ptr_buffer, + ptr_buffer->own_lines); + } + if (ptr_buffer->own_lines->prefix_max_length_refresh) + gui_line_compute_prefix_max_length (ptr_buffer->own_lines); + } + + /* compute buffer/prefix max length for mixed_lines */ + if (ptr_buffer->mixed_lines) + { + if (ptr_buffer->mixed_lines->buffer_max_length_refresh) + { + gui_line_compute_buffer_max_length (ptr_buffer, + ptr_buffer->mixed_lines); + } + if (ptr_buffer->mixed_lines->prefix_max_length_refresh) + gui_line_compute_prefix_max_length (ptr_buffer->mixed_lines); + } + } + /* refresh window if needed */ if (gui_window_refresh_needed) { diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 2f8352eb4..5b33a8c58 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -1013,7 +1013,7 @@ gui_buffer_set_short_name (struct t_gui_buffer *buffer, const char *short_name) strdup (short_name) : NULL; if (buffer->mixed_lines) - gui_line_compute_buffer_max_length (buffer, buffer->mixed_lines); + buffer->mixed_lines->buffer_max_length_refresh = 1; gui_buffer_ask_chat_refresh (buffer, 1); hook_signal_send ("buffer_renamed", @@ -2741,9 +2741,8 @@ gui_buffer_unmerge (struct t_gui_buffer *buffer, int number) if (ptr_new_active_buffer) { - gui_line_compute_prefix_max_length (ptr_new_active_buffer->mixed_lines); - gui_line_compute_buffer_max_length (ptr_new_active_buffer, - ptr_new_active_buffer->mixed_lines); + ptr_new_active_buffer->mixed_lines->prefix_max_length_refresh = 1; + ptr_new_active_buffer->mixed_lines->buffer_max_length_refresh = 1; } gui_window_ask_refresh (1); diff --git a/src/gui/gui-filter.c b/src/gui/gui-filter.c index 25f60a74a..9a4330d71 100644 --- a/src/gui/gui-filter.c +++ b/src/gui/gui-filter.c @@ -180,7 +180,7 @@ gui_filter_buffer (struct t_gui_buffer *buffer, } if (line_data) - gui_line_compute_prefix_max_length (line_data->buffer->lines); + line_data->buffer->lines->prefix_max_length_refresh = 1; if (buffer->lines->lines_hidden != lines_hidden) { diff --git a/src/gui/gui-line.c b/src/gui/gui-line.c index 33bc86d55..a283312e0 100644 --- a/src/gui/gui-line.c +++ b/src/gui/gui-line.c @@ -68,7 +68,9 @@ gui_lines_alloc () new_lines->first_line_not_read = 0; new_lines->lines_hidden = 0; new_lines->buffer_max_length = 0; + new_lines->buffer_max_length_refresh = 0; new_lines->prefix_max_length = CONFIG_INTEGER(config_look_prefix_align_min); + new_lines->prefix_max_length_refresh = 0; } return new_lines; @@ -711,6 +713,7 @@ gui_line_compute_buffer_max_length (struct t_gui_buffer *buffer, const char *short_name; lines->buffer_max_length = 0; + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) { @@ -722,6 +725,8 @@ gui_line_compute_buffer_max_length (struct t_gui_buffer *buffer, lines->buffer_max_length = length; } } + + lines->buffer_max_length_refresh = 0; } /* @@ -749,6 +754,8 @@ gui_line_compute_prefix_max_length (struct t_gui_lines *lines) lines->prefix_max_length = prefix_length; } } + + lines->prefix_max_length_refresh = 0; } /* @@ -792,7 +799,7 @@ gui_line_remove_from_list (struct t_gui_buffer *buffer, { struct t_gui_window *ptr_win; struct t_gui_window_scroll *ptr_scroll; - int update_prefix_max_length, prefix_length, prefix_is_nick; + int prefix_length, prefix_is_nick; for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) { @@ -815,8 +822,8 @@ gui_line_remove_from_list (struct t_gui_buffer *buffer, &prefix_is_nick); if (prefix_is_nick) prefix_length += config_length_nick_prefix_suffix; - update_prefix_max_length = - (prefix_length == lines->prefix_max_length); + if (prefix_length == lines->prefix_max_length) + lines->prefix_max_length_refresh = 1; /* move read marker if it was on line we are removing */ if (lines->last_read_line == line) @@ -853,10 +860,6 @@ gui_line_remove_from_list (struct t_gui_buffer *buffer, lines->lines_count--; free (line); - - /* compute "prefix_max_length" if needed */ - if (update_prefix_max_length) - gui_line_compute_prefix_max_length (lines); } /* @@ -1360,11 +1363,9 @@ gui_line_mix_buffers (struct t_gui_buffer *buffer) } } - /* compute "prefix_max_length" for mixed lines */ - gui_line_compute_prefix_max_length (new_lines); - - /* compute "buffer_max_length" for mixed lines */ - gui_line_compute_buffer_max_length (buffer, new_lines); + /* ask refresh of prefix/buffer max length for mixed lines */ + new_lines->prefix_max_length_refresh = 1; + new_lines->buffer_max_length_refresh = 1; /* free old mixed lines */ if (ptr_buffer_found->mixed_lines) @@ -1407,7 +1408,9 @@ gui_line_hdata_lines_cb (void *data, const char *hdata_name) HDATA_VAR(struct t_gui_lines, first_line_not_read, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_gui_lines, lines_hidden, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_gui_lines, buffer_max_length, INTEGER, 0, NULL, NULL); + HDATA_VAR(struct t_gui_lines, buffer_max_length_refresh, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_gui_lines, prefix_max_length, INTEGER, 0, NULL, NULL); + HDATA_VAR(struct t_gui_lines, prefix_max_length_refresh, INTEGER, 0, NULL, NULL); } return hdata; } @@ -1506,7 +1509,7 @@ gui_line_hdata_line_data_update_cb (void *data, hdata_set (hdata, pointer, "prefix", value); line_data->prefix_length = (line_data->prefix) ? gui_chat_strlen_screen (line_data->prefix) : 0; - gui_line_compute_prefix_max_length (line_data->buffer->lines); + line_data->buffer->lines->prefix_max_length_refresh = 1; rc++; update_coords = 1; } @@ -1654,13 +1657,15 @@ gui_lines_print_log (struct t_gui_lines *lines) { if (lines) { - log_printf (" first_line. . . . . . : 0x%lx", lines->first_line); - log_printf (" last_line . . . . . . : 0x%lx", lines->last_line); - log_printf (" last_read_line. . . . : 0x%lx", lines->last_read_line); - log_printf (" lines_count . . . . . : %d", lines->lines_count); - log_printf (" first_line_not_read . : %d", lines->first_line_not_read); - log_printf (" lines_hidden. . . . . : %d", lines->lines_hidden); - log_printf (" buffer_max_length . . : %d", lines->buffer_max_length); - log_printf (" prefix_max_length . . : %d", lines->prefix_max_length); + log_printf (" first_line . . . . . . . : 0x%lx", lines->first_line); + log_printf (" last_line. . . . . . . . : 0x%lx", lines->last_line); + log_printf (" last_read_line . . . . . : 0x%lx", lines->last_read_line); + log_printf (" lines_count. . . . . . . : %d", lines->lines_count); + log_printf (" first_line_not_read. . . : %d", lines->first_line_not_read); + log_printf (" lines_hidden . . . . . . : %d", lines->lines_hidden); + log_printf (" buffer_max_length. . . . : %d", lines->buffer_max_length); + log_printf (" buffer_max_length_refresh: %d", lines->buffer_max_length_refresh); + log_printf (" prefix_max_length. . . . : %d", lines->prefix_max_length); + log_printf (" prefix_max_length_refresh: %d", lines->prefix_max_length_refresh); } } diff --git a/src/gui/gui-line.h b/src/gui/gui-line.h index d09009380..483e53fce 100644 --- a/src/gui/gui-line.h +++ b/src/gui/gui-line.h @@ -60,7 +60,9 @@ struct t_gui_lines int lines_hidden; /* 1 if at least one line is hidden */ int buffer_max_length; /* max length for buffer name (for */ /* mixed lines only) */ + int buffer_max_length_refresh; /* refresh asked for buffer max len. */ int prefix_max_length; /* max length for prefix align */ + int prefix_max_length_refresh; /* refresh asked for prefix max len. */ }; /* line functions */