Skip to content

validateScruct can be slow #8638

@philipheinser

Description

@philipheinser

I added this patch to remove the call to superstruct from release build if you do a lot of logging in a list this call ads up and was really expensive. Maybe it is something that is interesting for other people as well. I could also do a poll request if helpful.

diff --git a/lib/struct.js b/lib/struct.js
index 0d820e070517d1a9882e3699b2e14030ee93a686..7599af00b2fd60f45021777338b68f72cff3b154 100644
--- a/lib/struct.js
+++ b/lib/struct.js
@@ -18,6 +18,10 @@ import { isUndefined } from '@react-native-firebase/app/lib/common/validate';
 import { create } from 'superstruct';
 
 export const validateStruct = (value = {}, struct, prefix = '') => {
+  if(!__DEV__) {
+    return value;
+  }
+
   try {
     return create(value, struct);
   } catch (e) {

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions