From 8d111da7f6f007fa226e3b171ce4af5a545663b1 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Thu, 10 Oct 2019 16:08:26 +0200 Subject: [PATCH] perf(ivy): use instanceof operator to check for NodeInjectorFactory instances (#33082) We used to have a custom version of the NodeInjectorFactory check that was supposed to be faster to the direct usage of the `instanceof` operator. This might have been the case in the past but the recent benchmark shows that using `instanceof` speeds up the `directive_instantiate` by ~10% (from time getting from ~340ms down to ~305ms). PR Close #33082 --- packages/core/src/render3/interfaces/injector.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/core/src/render3/interfaces/injector.ts b/packages/core/src/render3/interfaces/injector.ts index e524ce38d4..ad2ef16d05 100644 --- a/packages/core/src/render3/interfaces/injector.ts +++ b/packages/core/src/render3/interfaces/injector.ts @@ -242,9 +242,7 @@ export class NodeInjectorFactory { } export function isFactory(obj: any): obj is NodeInjectorFactory { - // See: https://jsperf.com/instanceof-vs-getprototypeof - return obj !== null && typeof obj == 'object' && - Object.getPrototypeOf(obj) == NodeInjectorFactory.prototype; + return obj instanceof NodeInjectorFactory; } // Note: This hack is necessary so we don't erroneously get a circular dependency