This is an automated email from the ASF dual-hosted git repository.

dkulp 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 e15c34c  Memory optimization in SchemaName.Fullname
e15c34c is described below

commit e15c34cc6ce7be9c172253ec528942aa8ded4ce1
Author: Meni Braun (MSFT) <[email protected]>
AuthorDate: Mon Aug 2 16:44:15 2021 +0300

    Memory optimization in SchemaName.Fullname
    
    FullName property is being called by `ClassCache.GetClass` for each 
property:
    ```csharp
    public DotnetClass GetClass(RecordSchema schema)
    {
        DotnetClass result;
        if (!this._nameClassMap.TryGetValue(schema.Fullname, ref result))
    .
    .
    ```
    
    This allocates TONS of strings on a scenario which calls 
`Avro.Reflect.ReflectDefaultWriter.WriteRecord` on large amount of entities 
(millions) + large amount of fields (tens).
---
 lang/csharp/src/apache/main/Schema/SchemaName.cs | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lang/csharp/src/apache/main/Schema/SchemaName.cs 
b/lang/csharp/src/apache/main/Schema/SchemaName.cs
index 29c5184..c23aa67 100644
--- a/lang/csharp/src/apache/main/Schema/SchemaName.cs
+++ b/lang/csharp/src/apache/main/Schema/SchemaName.cs
@@ -25,6 +25,9 @@ namespace Avro
     /// </summary>
     public class SchemaName
     {
+        // cache the full name, so it won't allocate new strings on each call
+        private String fullName;
+        
         /// <summary>
         /// Name of the schema
         /// </summary>
@@ -43,7 +46,7 @@ namespace Avro
         /// <summary>
         /// Namespace.Name of the schema
         /// </summary>
-        public String Fullname { get { return string.IsNullOrEmpty(Namespace) 
? this.Name : Namespace + "." + this.Name; } }
+        public String Fullname { get { return fullName; } }
 
         /// <summary>
         /// Namespace of the schema
@@ -78,6 +81,8 @@ namespace Avro
                 this.Name = parts[parts.Length - 1];
                 this.EncSpace = encspace;
             }
+            
+            fullName = string.IsNullOrEmpty(Namespace) ? this.Name : Namespace 
+ "." + this.Name;
         }
 
         /// <summary>

Reply via email to