AdrianStrugala / AvroConvert

Rapid Avro serializer for C# .NET
Other
97 stars 27 forks source link

Introduce a schema cache #127

Closed gmanvel closed 8 months ago

gmanvel commented 8 months ago

This PR introduces schema cache, so that Schema.Create(obj); does not create schema on every AvroConvert.Serializecall, which is currently defined as

public static byte[] Serialize(object obj, CodecType codecType)
        {
            using (MemoryStream resultStream = new MemoryStream())
            {
                var schema = Schema.Create(obj);
                using (var writer = new Encoder(schema, resultStream, codecType))
                {
                    writer.Append(obj);
                }
                byte[] result = resultStream.ToArray();
                return result;
            }
        }

Note, that it is caching only schemas when AvroConvertOptions are not passed.

AdrianStrugala commented 8 months ago

Thank you, another clever idea!