Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use source generator for type mapping #343

Open
alexeyzimarev opened this issue Jun 16, 2024 · 1 comment
Open

Use source generator for type mapping #343

alexeyzimarev opened this issue Jun 16, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@alexeyzimarev
Copy link
Contributor

Right now, mapping event types to classes is done using a dictionary. It requires either to register types explicitly or use assembly scanning and attributes. Assembly scanning works with EventType attribute. Dictionaries are relatively fast, but still slower than direct calls. For example, generic-based type map used to map commands to command handlers is by order of magnitude faster than the event type map.

As most of us use the attribute anyway, it should be possible to generate code for event type mapping, both forwards and backwards (type->name and name->type).

The first step could be eliminating assembly scanning, so Eventuous gets a bit closer to be AOT-compliant. The first iteration could generate code to add types and names to the existing TypeMap without assembly scanning at runtime.

The second step would be to generate a static function with a switch expression to replace the type map. However, it will kill the option to provide custom type maps and having multiple type maps in one application. However, I don't know how many people use that option and if it's useful at all.
Feedback about using multiple type maps within one app would be great.

@alexeyzimarev alexeyzimarev added Improvement enhancement New feature or request and removed Improvement labels Jun 16, 2024
Copy link

linear bot commented Aug 16, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant