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

Is it possible to make this aot-friendly? #185

Open
mattiasnordqvist opened this issue Dec 5, 2023 · 6 comments
Open

Is it possible to make this aot-friendly? #185

mattiasnordqvist opened this issue Dec 5, 2023 · 6 comments
Labels
enhancement Enhancement of an existing feature

Comments

@mattiasnordqvist
Copy link

It would be nice to get better performance!

@eduherminio
Copy link
Owner

Hi @mattiasnordqvist,

First of all, thanks for using AoCHelper and for raising this issue.

I'm happy to evaluate your feature request to make the library AOT friendly.

However, I'm surprised regarding the reason behind it, since in my experience, .NET Native AOT compiled code is generally slower than its equivalent JIT version (as of today). Less memory allocating, faster to start, smaller sized; but slower in its execution.

@mattiasnordqvist
Copy link
Author

Hi!

Thats interesting. I don't have much experience with AOT and I don't know really what I'm missing without JIT. Yesterday was the very first time I tried AOT actually. I compiled my solution for star 5 part 2 this year with AOT, and time taken executing the code dropped from above 6ms to just under 2ms. :) One of my collegues is solving in rust, and I thought aot could help me beat him. :P

@eduherminio
Copy link
Owner

What I would recommend you is to use BenchmarkDotNet to properly measure the performance of the code, AoCHelper results are just an approximation and you shouldn't rely on them for anything super serious, such as comparing your results with your colleagues 😜

Going back to the JIT/AOT topic, your mileage might vary of course, but some JIT optimizations take place when you run your code multiple times, one of the reasons why proper benchmarking methods such as BDN 'warm up' the code before executing it, even if they execute it multiple times.
But if you rather care about first time executions and don't wanna bother using BDN, chances are you can benefit from Native AOT in some cases 🙂

@eduherminio eduherminio added the enhancement Enhancement of an existing feature label Dec 13, 2023
@eduherminio
Copy link
Owner

eduherminio commented Nov 21, 2024

I've enabled AOT analyzers locally and they're emitting warnings about the usage of:

  • System.Reflection.Assembly.GetTypes(), used to locate the problem classes.
  • Activator.CreateInstance(Type), used to instantiate the problem classes.

I don't see an immediate way to achieve those two goals without reflection, so I don't see an easy way to make AoCHelper AOT-friendly as of now.

Please let me know if you come up with any ideas how to achieve this goal

@mattiasnordqvist
Copy link
Author

Source generators would do it. I might try it someday

@eduherminio
Copy link
Owner

Yeah, I've been playing with them lately and they could be an option, maybe something like Apparatus.AOT.Reflection would be useful or serve an inspiration.

Given it's already end of November, I'll have to ship v4 later later this week (adding .NET 9 support and dropping .NET 6 and 7 one) without having addressed this issue yet, I'm afraid.

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

No branches or pull requests

2 participants