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).
This commit is contained in:
David Taylor 2023-08-21 13:42:59 +01:00 committed by GitHub
parent c48e29db02
commit 121cd886a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View File

@ -22,7 +22,7 @@
{{/if}}
{{/each}}
</this.wrapperComponent>
{{else}}
{{else if this.connectorsExist}}
{{! The modern path: no wrapper element = no classic component }}
{{#each this.connectors as |c|}}
{{#if c.componentClass}}

View File

@ -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

View File

@ -165,6 +165,13 @@ function buildConnectorCache() {
}
}
export function connectorsExist(outletName) {
if (!_connectorCache) {
buildConnectorCache();
}
return Boolean(_connectorCache[outletName]);
}
export function connectorsFor(outletName) {
if (!_connectorCache) {
buildConnectorCache();