Skip to content

[Feature Request]: DefaultTypeResolver caching #437

@adambajguz

Description

@adambajguz

Is your request related to a problem you have?

I think adding a cache in DefaultTypeResolver can improve performance and memoery allocations.

Describe the solution you'd like

private readonly ConcurrentDictionary<string, Type> _consumeTypeCache = new(StringComparer.Ordinal);
private readonly ConcurrentDictionary<Type, string> _produceTypeCache = new();

(...)
return typeName is null ?
   null :
   _consumeTypeCache.GetOrAdd(typeName, Type.GetType);

(...)

string messageTypeName = _produceTypeCache.GetOrAdd(
    messageType,
    static messageType => $"{messageType.FullName}, {messageType.Assembly.GetName().Name}");

context.Headers.SetString(MessageType, messageTypeName);

Are you able to help bring it to life and contribute with a Pull Request?

Yes

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions