Skip to content

Commit 0db46cf

Browse files
perf: Avoid unnecessary String construction in CustomClassMapper
This change optimizes the CustomClassMapper by avoiding the construction of the "No setter/field" error message when both throwOnUnknownProperties and warnOnUnknownProperties are false. This scenario occurs commonly when using @IgnoreExtraProperties. Benchmark results show a ~28x improvement for deserializing objects with many unknown properties. Co-authored-by: lahirumaramba <55609+lahirumaramba@users.noreply.github.com>
1 parent b095a06 commit 0db46cf

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

src/main/java/com/google/firebase/database/utilities/encoding/CustomClassMapper.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -730,19 +730,21 @@ public T deserialize(Map<String, Object> values, Map<TypeVariable<Class<T>>, Typ
730730
throw new RuntimeException(e);
731731
}
732732
} else {
733-
String message =
734-
"No setter/field for "
735-
+ propertyName
736-
+ " found "
737-
+ "on class "
738-
+ this.clazz.getName();
739-
if (this.properties.containsKey(propertyName.toLowerCase())) {
740-
message += " (fields/setters are case sensitive!)";
741-
}
742-
if (this.throwOnUnknownProperties) {
743-
throw new DatabaseException(message);
744-
} else if (this.warnOnUnknownProperties) {
745-
logger.warn(message);
733+
if (this.throwOnUnknownProperties || this.warnOnUnknownProperties) {
734+
String message =
735+
"No setter/field for "
736+
+ propertyName
737+
+ " found "
738+
+ "on class "
739+
+ this.clazz.getName();
740+
if (this.properties.containsKey(propertyName.toLowerCase())) {
741+
message += " (fields/setters are case sensitive!)";
742+
}
743+
if (this.throwOnUnknownProperties) {
744+
throw new DatabaseException(message);
745+
} else if (this.warnOnUnknownProperties) {
746+
logger.warn(message);
747+
}
746748
}
747749
}
748750
}

0 commit comments

Comments
 (0)