Skip to content

Commit 016038d

Browse files
showelltimabbott
authored andcommitted
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.
1 parent 4bcf713 commit 016038d

File tree

9 files changed

+33
-38
lines changed

9 files changed

+33
-38
lines changed

frontend_tests/zjsunit/zblueslip.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ exports.make_zblueslip = function () {
119119
return ex.message;
120120
};
121121

122-
lib.start_timing = () => () => {};
122+
lib.measure_time = (label, f) => {
123+
f();
124+
};
123125

124126
lib.preview_node = (node) => "node:" + node;
125127

static/js/activity.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,9 @@ exports.build_user_sidebar = function () {
112112

113113
const user_ids = buddy_data.get_filtered_and_sorted_user_ids(filter_text);
114114

115-
const finish = blueslip.start_timing("buddy_list.populate");
116-
buddy_list.populate({
117-
keys: user_ids,
115+
blueslip.measure_time("buddy_list.populate", () => {
116+
buddy_list.populate({keys: user_ids});
118117
});
119-
finish();
120118

121119
return user_ids; // for testing
122120
};

static/js/blueslip.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,12 @@ exports.error = function blueslip_error(msg, more_info, stack) {
251251

252252
exports.timings = new Map();
253253

254-
exports.start_timing = function (label) {
254+
exports.measure_time = function (label, f) {
255255
const t1 = performance.now();
256-
257-
return function () {
258-
const t2 = performance.now();
259-
const elapsed = t2 - t1;
260-
exports.timings.set(label, elapsed);
261-
};
256+
f();
257+
const t2 = performance.now();
258+
const elapsed = t2 - t1;
259+
exports.timings.set(label, elapsed);
262260
};
263261

264262
// Produces an easy-to-read preview on an HTML element. Currently

static/js/list_widget.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ exports.create = function ($container, list, opts) {
186186

187187
const slice = meta.filtered_list.slice(meta.offset, meta.offset + load_count);
188188

189-
const finish = blueslip.start_timing("ListWidget " + opts.name);
190189
let html = "";
191190
for (const item of slice) {
192191
const s = opts.modifier(item);
@@ -202,8 +201,6 @@ exports.create = function ($container, list, opts) {
202201
}
203202
}
204203

205-
finish();
206-
207204
$container.append($(html));
208205
meta.offset += load_count;
209206
};

static/js/pm_list.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,8 @@ exports._get_convos = function () {
106106
};
107107

108108
exports._build_private_messages_list = function () {
109-
const finish = blueslip.start_timing("render pm list");
110109
const convos = exports._get_convos();
111110
const dom_ast = pm_list_dom.pm_ul(convos);
112-
finish();
113111
return dom_ast;
114112
};
115113

static/js/stream_create.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,18 @@ exports.show_new_stream_modal = function () {
257257
$("#stream-creation").removeClass("hide");
258258
$(".right .settings").hide();
259259

260-
const finish = blueslip.start_timing("render new stream users");
261-
const all_users = people.get_people_for_stream_create();
262-
// Add current user on top of list
263-
all_users.unshift(people.get_by_user_id(page_params.user_id));
264-
const html = render_new_stream_users({
265-
users: all_users,
266-
streams: stream_data.get_streams_for_settings_page(),
267-
is_admin: page_params.is_admin,
260+
let html;
261+
262+
blueslip.measure_time("render new stream users", () => {
263+
const all_users = people.get_people_for_stream_create();
264+
// Add current user on top of list
265+
all_users.unshift(people.get_by_user_id(page_params.user_id));
266+
html = render_new_stream_users({
267+
users: all_users,
268+
streams: stream_data.get_streams_for_settings_page(),
269+
is_admin: page_params.is_admin,
270+
});
268271
});
269-
finish();
270272

271273
const container = $("#people_to_add");
272274
container.html(html);

static/js/stream_list.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,8 @@ function set_stream_unread_count(stream_id, count) {
314314
}
315315

316316
exports.update_streams_sidebar = function (force_rerender) {
317-
const finish = blueslip.start_timing("build_stream_list");
318317
exports.build_stream_list(force_rerender);
319-
finish();
318+
320319
exports.stream_cursor.redraw();
321320

322321
if (!narrow_state.active()) {

static/js/subs.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -400,15 +400,16 @@ function get_stream_id_buckets(stream_ids, query) {
400400
}
401401

402402
exports.populate_stream_settings_left_panel = function () {
403-
const finish = blueslip.start_timing("render left panel");
404-
const sub_rows = stream_data.get_updated_unsorted_subs();
403+
let html;
404+
blueslip.measure_time("render left panel", () => {
405+
const sub_rows = stream_data.get_updated_unsorted_subs();
405406

406-
const template_data = {
407-
subscriptions: sub_rows,
408-
};
407+
const template_data = {
408+
subscriptions: sub_rows,
409+
};
409410

410-
const html = render_subscriptions(template_data);
411-
finish();
411+
html = render_subscriptions(template_data);
412+
});
412413

413414
ui.get_content_element($("#subscriptions_table .streams-list")).html(html);
414415
};

static/js/ui_init.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ exports.initialize_everything = function () {
482482
};
483483

484484
$(() => {
485-
const finish = blueslip.start_timing("initialize_everything");
486-
exports.initialize_everything();
487-
finish();
485+
blueslip.measure_time("initialize_everything", () => {
486+
exports.initialize_everything();
487+
});
488488
});

0 commit comments

Comments
 (0)