mirror of https://github.com/zulip/zulip.git
blueslip: Add measure_time wrapper.
Now when we want to measure how long a block of code takes to execute, we just wrap it with `blueslip.measure_time`, instead of the awkward idiom from my original commit of getting a callback function. My rationale for the original scheme was that I wanted to minimize diffs and avoid changing `const` to `let` in a few cases, but I believe now that the function wrapper is nicer. In a few cases I just removed the blueslip timing code, since I was able to confirm on czo that the times were pretty minimal.
This commit is contained in:
parent
4bcf7131c1
commit
016038dcd1
|
@ -119,7 +119,9 @@ exports.make_zblueslip = function () {
|
|||
return ex.message;
|
||||
};
|
||||
|
||||
lib.start_timing = () => () => {};
|
||||
lib.measure_time = (label, f) => {
|
||||
f();
|
||||
};
|
||||
|
||||
lib.preview_node = (node) => "node:" + node;
|
||||
|
||||
|
|
|
@ -112,11 +112,9 @@ 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,
|
||||
blueslip.measure_time("buddy_list.populate", () => {
|
||||
buddy_list.populate({keys: user_ids});
|
||||
});
|
||||
finish();
|
||||
|
||||
return user_ids; // for testing
|
||||
};
|
||||
|
|
|
@ -251,14 +251,12 @@ exports.error = function blueslip_error(msg, more_info, stack) {
|
|||
|
||||
exports.timings = new Map();
|
||||
|
||||
exports.start_timing = function (label) {
|
||||
exports.measure_time = function (label, f) {
|
||||
const t1 = performance.now();
|
||||
|
||||
return function () {
|
||||
const t2 = performance.now();
|
||||
const elapsed = t2 - t1;
|
||||
exports.timings.set(label, elapsed);
|
||||
};
|
||||
f();
|
||||
const t2 = performance.now();
|
||||
const elapsed = t2 - t1;
|
||||
exports.timings.set(label, elapsed);
|
||||
};
|
||||
|
||||
// Produces an easy-to-read preview on an HTML element. Currently
|
||||
|
|
|
@ -186,7 +186,6 @@ exports.create = function ($container, list, opts) {
|
|||
|
||||
const slice = meta.filtered_list.slice(meta.offset, meta.offset + load_count);
|
||||
|
||||
const finish = blueslip.start_timing("ListWidget " + opts.name);
|
||||
let html = "";
|
||||
for (const item of slice) {
|
||||
const s = opts.modifier(item);
|
||||
|
@ -202,8 +201,6 @@ exports.create = function ($container, list, opts) {
|
|||
}
|
||||
}
|
||||
|
||||
finish();
|
||||
|
||||
$container.append($(html));
|
||||
meta.offset += load_count;
|
||||
};
|
||||
|
|
|
@ -106,10 +106,8 @@ exports._get_convos = function () {
|
|||
};
|
||||
|
||||
exports._build_private_messages_list = function () {
|
||||
const finish = blueslip.start_timing("render pm list");
|
||||
const convos = exports._get_convos();
|
||||
const dom_ast = pm_list_dom.pm_ul(convos);
|
||||
finish();
|
||||
return dom_ast;
|
||||
};
|
||||
|
||||
|
|
|
@ -257,16 +257,18 @@ exports.show_new_stream_modal = function () {
|
|||
$("#stream-creation").removeClass("hide");
|
||||
$(".right .settings").hide();
|
||||
|
||||
const finish = blueslip.start_timing("render new stream users");
|
||||
const all_users = people.get_people_for_stream_create();
|
||||
// Add current user on top of list
|
||||
all_users.unshift(people.get_by_user_id(page_params.user_id));
|
||||
const html = render_new_stream_users({
|
||||
users: all_users,
|
||||
streams: stream_data.get_streams_for_settings_page(),
|
||||
is_admin: page_params.is_admin,
|
||||
let html;
|
||||
|
||||
blueslip.measure_time("render new stream users", () => {
|
||||
const all_users = people.get_people_for_stream_create();
|
||||
// Add current user on top of list
|
||||
all_users.unshift(people.get_by_user_id(page_params.user_id));
|
||||
html = render_new_stream_users({
|
||||
users: all_users,
|
||||
streams: stream_data.get_streams_for_settings_page(),
|
||||
is_admin: page_params.is_admin,
|
||||
});
|
||||
});
|
||||
finish();
|
||||
|
||||
const container = $("#people_to_add");
|
||||
container.html(html);
|
||||
|
|
|
@ -314,9 +314,8 @@ function set_stream_unread_count(stream_id, count) {
|
|||
}
|
||||
|
||||
exports.update_streams_sidebar = function (force_rerender) {
|
||||
const finish = blueslip.start_timing("build_stream_list");
|
||||
exports.build_stream_list(force_rerender);
|
||||
finish();
|
||||
|
||||
exports.stream_cursor.redraw();
|
||||
|
||||
if (!narrow_state.active()) {
|
||||
|
|
|
@ -400,15 +400,16 @@ function get_stream_id_buckets(stream_ids, query) {
|
|||
}
|
||||
|
||||
exports.populate_stream_settings_left_panel = function () {
|
||||
const finish = blueslip.start_timing("render left panel");
|
||||
const sub_rows = stream_data.get_updated_unsorted_subs();
|
||||
let html;
|
||||
blueslip.measure_time("render left panel", () => {
|
||||
const sub_rows = stream_data.get_updated_unsorted_subs();
|
||||
|
||||
const template_data = {
|
||||
subscriptions: sub_rows,
|
||||
};
|
||||
const template_data = {
|
||||
subscriptions: sub_rows,
|
||||
};
|
||||
|
||||
const html = render_subscriptions(template_data);
|
||||
finish();
|
||||
html = render_subscriptions(template_data);
|
||||
});
|
||||
|
||||
ui.get_content_element($("#subscriptions_table .streams-list")).html(html);
|
||||
};
|
||||
|
|
|
@ -482,7 +482,7 @@ exports.initialize_everything = function () {
|
|||
};
|
||||
|
||||
$(() => {
|
||||
const finish = blueslip.start_timing("initialize_everything");
|
||||
exports.initialize_everything();
|
||||
finish();
|
||||
blueslip.measure_time("initialize_everything", () => {
|
||||
exports.initialize_everything();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue