mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
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:
@@ -119,7 +119,9 @@ exports.make_zblueslip = function () {
|
|||||||
return ex.message;
|
return ex.message;
|
||||||
};
|
};
|
||||||
|
|
||||||
lib.start_timing = () => () => {};
|
lib.measure_time = (label, f) => {
|
||||||
|
f();
|
||||||
|
};
|
||||||
|
|
||||||
lib.preview_node = (node) => "node:" + node;
|
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 user_ids = buddy_data.get_filtered_and_sorted_user_ids(filter_text);
|
||||||
|
|
||||||
const finish = blueslip.start_timing("buddy_list.populate");
|
blueslip.measure_time("buddy_list.populate", () => {
|
||||||
buddy_list.populate({
|
buddy_list.populate({keys: user_ids});
|
||||||
keys: user_ids,
|
|
||||||
});
|
});
|
||||||
finish();
|
|
||||||
|
|
||||||
return user_ids; // for testing
|
return user_ids; // for testing
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -251,14 +251,12 @@ exports.error = function blueslip_error(msg, more_info, stack) {
|
|||||||
|
|
||||||
exports.timings = new Map();
|
exports.timings = new Map();
|
||||||
|
|
||||||
exports.start_timing = function (label) {
|
exports.measure_time = function (label, f) {
|
||||||
const t1 = performance.now();
|
const t1 = performance.now();
|
||||||
|
f();
|
||||||
return function () {
|
const t2 = performance.now();
|
||||||
const t2 = performance.now();
|
const elapsed = t2 - t1;
|
||||||
const elapsed = t2 - t1;
|
exports.timings.set(label, elapsed);
|
||||||
exports.timings.set(label, elapsed);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Produces an easy-to-read preview on an HTML element. Currently
|
// 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 slice = meta.filtered_list.slice(meta.offset, meta.offset + load_count);
|
||||||
|
|
||||||
const finish = blueslip.start_timing("ListWidget " + opts.name);
|
|
||||||
let html = "";
|
let html = "";
|
||||||
for (const item of slice) {
|
for (const item of slice) {
|
||||||
const s = opts.modifier(item);
|
const s = opts.modifier(item);
|
||||||
@@ -202,8 +201,6 @@ exports.create = function ($container, list, opts) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
finish();
|
|
||||||
|
|
||||||
$container.append($(html));
|
$container.append($(html));
|
||||||
meta.offset += load_count;
|
meta.offset += load_count;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -106,10 +106,8 @@ exports._get_convos = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports._build_private_messages_list = function () {
|
exports._build_private_messages_list = function () {
|
||||||
const finish = blueslip.start_timing("render pm list");
|
|
||||||
const convos = exports._get_convos();
|
const convos = exports._get_convos();
|
||||||
const dom_ast = pm_list_dom.pm_ul(convos);
|
const dom_ast = pm_list_dom.pm_ul(convos);
|
||||||
finish();
|
|
||||||
return dom_ast;
|
return dom_ast;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -257,16 +257,18 @@ exports.show_new_stream_modal = function () {
|
|||||||
$("#stream-creation").removeClass("hide");
|
$("#stream-creation").removeClass("hide");
|
||||||
$(".right .settings").hide();
|
$(".right .settings").hide();
|
||||||
|
|
||||||
const finish = blueslip.start_timing("render new stream users");
|
let html;
|
||||||
const all_users = people.get_people_for_stream_create();
|
|
||||||
// Add current user on top of list
|
blueslip.measure_time("render new stream users", () => {
|
||||||
all_users.unshift(people.get_by_user_id(page_params.user_id));
|
const all_users = people.get_people_for_stream_create();
|
||||||
const html = render_new_stream_users({
|
// Add current user on top of list
|
||||||
users: all_users,
|
all_users.unshift(people.get_by_user_id(page_params.user_id));
|
||||||
streams: stream_data.get_streams_for_settings_page(),
|
html = render_new_stream_users({
|
||||||
is_admin: page_params.is_admin,
|
users: all_users,
|
||||||
|
streams: stream_data.get_streams_for_settings_page(),
|
||||||
|
is_admin: page_params.is_admin,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
finish();
|
|
||||||
|
|
||||||
const container = $("#people_to_add");
|
const container = $("#people_to_add");
|
||||||
container.html(html);
|
container.html(html);
|
||||||
|
|||||||
@@ -314,9 +314,8 @@ function set_stream_unread_count(stream_id, count) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.update_streams_sidebar = function (force_rerender) {
|
exports.update_streams_sidebar = function (force_rerender) {
|
||||||
const finish = blueslip.start_timing("build_stream_list");
|
|
||||||
exports.build_stream_list(force_rerender);
|
exports.build_stream_list(force_rerender);
|
||||||
finish();
|
|
||||||
exports.stream_cursor.redraw();
|
exports.stream_cursor.redraw();
|
||||||
|
|
||||||
if (!narrow_state.active()) {
|
if (!narrow_state.active()) {
|
||||||
|
|||||||
@@ -400,15 +400,16 @@ function get_stream_id_buckets(stream_ids, query) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.populate_stream_settings_left_panel = function () {
|
exports.populate_stream_settings_left_panel = function () {
|
||||||
const finish = blueslip.start_timing("render left panel");
|
let html;
|
||||||
const sub_rows = stream_data.get_updated_unsorted_subs();
|
blueslip.measure_time("render left panel", () => {
|
||||||
|
const sub_rows = stream_data.get_updated_unsorted_subs();
|
||||||
|
|
||||||
const template_data = {
|
const template_data = {
|
||||||
subscriptions: sub_rows,
|
subscriptions: sub_rows,
|
||||||
};
|
};
|
||||||
|
|
||||||
const html = render_subscriptions(template_data);
|
html = render_subscriptions(template_data);
|
||||||
finish();
|
});
|
||||||
|
|
||||||
ui.get_content_element($("#subscriptions_table .streams-list")).html(html);
|
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");
|
blueslip.measure_time("initialize_everything", () => {
|
||||||
exports.initialize_everything();
|
exports.initialize_everything();
|
||||||
finish();
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user