You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by cu...@apache.org on 2018/03/02 22:31:52 UTC
[avro] branch master updated: AVRO-2147. Java Protobuf: use schema
cache to improve performance. (Tobi Vollebregt via cutting)
This is an automated email from the ASF dual-hosted git repository.
cutting pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/master by this push:
new 94f12b8 AVRO-2147. Java Protobuf: use schema cache to improve performance. (Tobi Vollebregt via cutting)
94f12b8 is described below
commit 94f12b85c3d269cdb510f8c0b843008469e4f826
Author: Doug Cutting <cu...@apache.org>
AuthorDate: Fri Mar 2 14:20:50 2018 -0800
AVRO-2147. Java Protobuf: use schema cache to improve performance. (Tobi Vollebregt via cutting)
---
.../src/main/java/org/apache/avro/protobuf/ProtobufData.java | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java b/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
index e351422..b07b7f3 100644
--- a/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
+++ b/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
@@ -158,10 +158,17 @@ public class ProtobufData extends GenericData {
@Override
protected Schema getRecordSchema(Object record) {
- return getSchema(((Message)record).getDescriptorForType());
+ Descriptor descriptor = ((Message)record).getDescriptorForType();
+ Schema schema = schemaCache.get(descriptor);
+
+ if (schema == null) {
+ schema = getSchema(descriptor);
+ schemaCache.put(descriptor, schema);
+ }
+ return schema;
}
- private final Map<Class,Schema> schemaCache
+ private final Map<Object,Schema> schemaCache
= new ConcurrentHashMap<>();
/** Return a record schema given a protobuf message class. */
--
To stop receiving notification emails like this one, please contact
cutting@apache.org.