Skip to content

Commit 26ef9f2

Browse files
committed
fix: various preformace imporvements
1) getObjectOrInterfaceTypeNameIfExists - This function was not fixed on the move to map based metadata storage. Now instead of looking inside an entire metadata array, it fetches the item from the map 2) MetadataCollectionModel - I noticed that the interfaces list recieves duplicate instances of the same interface, so I switched the implementation to a map to remvoe duplicates. 3) LazyMetadataStorageHost.load - In very large applications (ie several millions of metadata object) we encountered an invalid arugments size thrown from V8, this is because the spread operator behind the scenes translates the values to multiple arguments. Switching to flat() solves this issue. 4) GraphQLSchemaFactory.create & LazyMetadataStorageHost.updateStorage - We noticed that the entire GQL metadata model was being rebuilt several times during the bootstrap of the application, I assume this was done because of the need to clear and rebuild the arrays every time. Now when we use maps we can't get duplicates in the metadata store, so I verify that the updateStorage callback is called only once, and I removed the clear call from the GraphQLSchemaFactory.create(). This results in a tremendous memory consumption boost! (in our case, from 8GB to 700MB)
1 parent 2b26ac4 commit 26ef9f2

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

packages/graphql/lib/decorators/resolver.decorator.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ function getObjectOrInterfaceTypeNameIfExists(
2323
const objectMetadata =
2424
TypeMetadataStorage.getObjectTypeMetadataByTarget(ctor);
2525
if (!objectMetadata) {
26-
const interfaceTypesMetadata = TypeMetadataStorage.getInterfacesMetadata();
27-
const interfaceMetadata = interfaceTypesMetadata.find(
28-
(type) => type.target === ctor,
29-
);
26+
const interfaceMetadata =
27+
TypeMetadataStorage.getInterfacesMetadata(ctor);
3028
if (!interfaceMetadata) {
3129
return;
3230
}

0 commit comments

Comments
 (0)