From 121cd886a4fa2304c8b70e8c87d31d9516559c39 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 21 Aug 2023 13:42:59 +0100 Subject: [PATCH] PERF: Improve rendering performance of empty PluginOutlets (#23165) This commit introduces a 'shortcut' when rendering PluginOutlets which have no registered connectors. On my machine, this improves rendering performance of empty PluginOutlets by around 30-40% (tested by running tachometer on a `/latest` route with 600 plugin outlets). --- .../javascripts/discourse/app/components/plugin-outlet.hbs | 2 +- .../javascripts/discourse/app/components/plugin-outlet.js | 5 +++++ .../javascripts/discourse/app/lib/plugin-connectors.js | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/app/components/plugin-outlet.hbs b/app/assets/javascripts/discourse/app/components/plugin-outlet.hbs index 2639a58e88a..acf2e087f05 100644 --- a/app/assets/javascripts/discourse/app/components/plugin-outlet.hbs +++ b/app/assets/javascripts/discourse/app/components/plugin-outlet.hbs @@ -22,7 +22,7 @@ {{/if}} {{/each}} -{{else}} +{{else if this.connectorsExist}} {{! The modern path: no wrapper element = no classic component }} {{#each this.connectors as |c|}} {{#if c.componentClass}} diff --git a/app/assets/javascripts/discourse/app/components/plugin-outlet.js b/app/assets/javascripts/discourse/app/components/plugin-outlet.js index 840c8b73f32..0fc1af240fb 100644 --- a/app/assets/javascripts/discourse/app/components/plugin-outlet.js +++ b/app/assets/javascripts/discourse/app/components/plugin-outlet.js @@ -3,6 +3,7 @@ import ClassicComponent from "@ember/component"; import { buildArgsWithDeprecations, + connectorsExist, renderedConnectorsFor, } from "discourse/lib/plugin-connectors"; import { helperContext } from "discourse-common/lib/helpers"; @@ -86,6 +87,10 @@ export default class PluginOutletComponent extends GlimmerComponentWithDeprecate ); } + get connectorsExist() { + return connectorsExist(this.args.name); + } + // Traditionally, pluginOutlets had an argument named 'args'. However, that name is reserved // in recent versions of ember so we need to migrate to outletArgs @cached diff --git a/app/assets/javascripts/discourse/app/lib/plugin-connectors.js b/app/assets/javascripts/discourse/app/lib/plugin-connectors.js index 2a7e1411f8a..8960ab848b7 100644 --- a/app/assets/javascripts/discourse/app/lib/plugin-connectors.js +++ b/app/assets/javascripts/discourse/app/lib/plugin-connectors.js @@ -165,6 +165,13 @@ function buildConnectorCache() { } } +export function connectorsExist(outletName) { + if (!_connectorCache) { + buildConnectorCache(); + } + return Boolean(_connectorCache[outletName]); +} + export function connectorsFor(outletName) { if (!_connectorCache) { buildConnectorCache();