mirror of https://github.com/zulip/zulip.git
blueslip: Add feature to time common operations.
This is relatively unobtrusive, and we don't send anything to the server. But any user can now enter blueslip.timings in the console to see a map of how long things take in milliseconds. We only record one timing per event label (i.e. the most recent). It's pretty easy to test this by just clicking around. For 300 users/streams most things are fast except for: - initialize_everything - manage streams (render_subscriptions) Both do lots of nontrivial work, although "manage streams" is a bit surprising, since we're only measuring how long to build the HTML from the templates (whereas the real time is probably browser rendering costs).
This commit is contained in:
parent
b8f9f6018a
commit
0aa9decd86
|
@ -97,6 +97,7 @@ const messages = {
|
|||
const noop = () => undefined;
|
||||
|
||||
set_global('alert_words', {});
|
||||
set_global('blueslip', global.make_zblueslip());
|
||||
|
||||
alert_words.process_message = noop;
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@ set_global('Element', function () {
|
|||
return { };
|
||||
});
|
||||
|
||||
set_global('blueslip', global.make_zblueslip());
|
||||
|
||||
// We only need very simple jQuery wrappers for when the
|
||||
// "real" code wraps html or sets up click handlers.
|
||||
// We'll simulate most other objects ourselves.
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
set_global('document', 'document-stub');
|
||||
set_global('$', global.make_zjquery());
|
||||
set_global('blueslip', global.make_zblueslip());
|
||||
|
||||
const Dict = zrequire('dict').Dict;
|
||||
const FoldDict = zrequire('fold_dict').FoldDict;
|
||||
|
|
|
@ -8,6 +8,7 @@ zrequire('util');
|
|||
zrequire('stream_data');
|
||||
zrequire('search_util');
|
||||
set_global('page_params', {});
|
||||
set_global('blueslip', global.make_zblueslip());
|
||||
|
||||
set_global('location', {
|
||||
hash: "#streams/1/announce",
|
||||
|
|
|
@ -79,5 +79,9 @@ exports.make_zblueslip = function (opts) {
|
|||
return ex.message;
|
||||
};
|
||||
|
||||
lib.start_timing = () => {
|
||||
return () => {};
|
||||
};
|
||||
|
||||
return lib;
|
||||
};
|
||||
|
|
|
@ -205,9 +205,11 @@ exports.build_user_sidebar = function () {
|
|||
|
||||
const user_ids = buddy_data.get_filtered_and_sorted_user_ids(filter_text);
|
||||
|
||||
const finish = blueslip.start_timing('buddy_list.populate');
|
||||
buddy_list.populate({
|
||||
keys: user_ids,
|
||||
});
|
||||
finish();
|
||||
|
||||
resize.resize_page_components();
|
||||
|
||||
|
|
|
@ -258,6 +258,18 @@ exports.fatal = function blueslip_fatal(msg, more_info) {
|
|||
throw new BlueslipError(msg, more_info);
|
||||
};
|
||||
|
||||
exports.timings = new Map();
|
||||
|
||||
exports.start_timing = function (label) {
|
||||
const t1 = performance.now();
|
||||
|
||||
return function () {
|
||||
const t2 = performance.now();
|
||||
const elapsed = t2 - t1;
|
||||
exports.timings.set(label, elapsed);
|
||||
};
|
||||
};
|
||||
|
||||
// Produces an easy-to-read preview on an HTML element. Currently
|
||||
// only used for including in error report emails; be sure to discuss
|
||||
// with other developers before using it in a user-facing context
|
||||
|
|
|
@ -92,6 +92,7 @@ exports.create = function ($container, list, opts) {
|
|||
|
||||
const slice = meta.filtered_list.slice(meta.offset, meta.offset + load_count);
|
||||
|
||||
const finish = blueslip.start_timing('list_render ' + opts.name);
|
||||
const html = _.reduce(slice, function (acc, item) {
|
||||
let _item = opts.modifier(item);
|
||||
|
||||
|
@ -119,6 +120,8 @@ exports.create = function ($container, list, opts) {
|
|||
return acc + (_item || "");
|
||||
}, "");
|
||||
|
||||
finish();
|
||||
|
||||
$container.append($(html));
|
||||
meta.offset += load_count;
|
||||
|
||||
|
|
|
@ -118,9 +118,11 @@ exports._build_private_messages_list = function () {
|
|||
display_messages.push(display_message);
|
||||
});
|
||||
|
||||
const finish = blueslip.start_timing('render pm list');
|
||||
const recipients_dom = render_sidebar_private_message_list({
|
||||
messages: display_messages,
|
||||
});
|
||||
finish();
|
||||
return recipients_dom;
|
||||
};
|
||||
|
||||
|
|
|
@ -301,7 +301,9 @@ function set_stream_unread_count(stream_id, count) {
|
|||
}
|
||||
|
||||
exports.update_streams_sidebar = function () {
|
||||
const finish = blueslip.start_timing('build_stream_list');
|
||||
exports.build_stream_list();
|
||||
finish();
|
||||
exports.stream_cursor.redraw();
|
||||
|
||||
if (!narrow_state.active()) {
|
||||
|
|
|
@ -381,10 +381,15 @@ function get_stream_id_buckets(stream_ids, query) {
|
|||
|
||||
exports.populate_stream_settings_left_panel = function () {
|
||||
const sub_rows = stream_data.get_updated_unsorted_subs();
|
||||
|
||||
const template_data = {
|
||||
subscriptions: sub_rows,
|
||||
};
|
||||
|
||||
const finish = blueslip.start_timing('render_subscriptions');
|
||||
const html = render_subscriptions(template_data);
|
||||
finish();
|
||||
|
||||
ui.get_content_element($('#subscriptions_table .streams-list')).html(html);
|
||||
};
|
||||
|
||||
|
|
|
@ -356,5 +356,7 @@ exports.initialize_everything = function () {
|
|||
};
|
||||
|
||||
$(function () {
|
||||
const finish = blueslip.start_timing('initialize_everything');
|
||||
exports.initialize_everything();
|
||||
finish();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue