From ea9212a92d5aff51f90d704d0378641b2bd1959a Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 4 Feb 2020 14:48:49 -0800 Subject: [PATCH] babel: Enable loose mode. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Due to try-catch deoptimization, Babel strict mode for…of loops run about 5× slower in Firefox than Babel loose mode for…of, native for…of, or forEach (which are all about the same speed). Chrome doesn’t seem to care. For some reason we need to explicitly add the core-js Symbol polyfill near the beginning of the common bundle. Otherwise it gets loaded at the wrong time and the Casper tests fail. Signed-off-by: Anders Kaseorg --- babel.config.js | 1 + static/js/bundles/common.js | 1 + static/js/unread.js | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/babel.config.js b/babel.config.js index f3315bbd44..2e9a4a5ddb 100644 --- a/babel.config.js +++ b/babel.config.js @@ -4,6 +4,7 @@ module.exports = { "@babel/preset-env", { corejs: 3, + loose: true, // Loose mode for…of loops are 5× faster in Firefox useBuiltIns: "usage", }, ], diff --git a/static/js/bundles/common.js b/static/js/bundles/common.js index ffe04c178a..fca9df10f2 100644 --- a/static/js/bundles/common.js +++ b/static/js/bundles/common.js @@ -1,4 +1,5 @@ import "core-js/features/promise"; +import "core-js/features/symbol"; import "jquery/dist/jquery.js"; import "underscore/underscore.js"; import "../page_params.js"; diff --git a/static/js/unread.js b/static/js/unread.js index e7a4c90bbe..e8889833e9 100644 --- a/static/js/unread.js +++ b/static/js/unread.js @@ -297,7 +297,7 @@ exports.unread_topic_counter = (function () { return { pretty_name: topic_name, - message_id: Math.max(...msgs), + message_id: Math.max(...Array.from(msgs)), }; });