CarterCommunity / Carter

Carter is framework that is a thin layer of extension methods and functionality over ASP.NET Core allowing code to be more explicit and most importantly more enjoyable.
MIT License
2.05k stars 172 forks source link

Possible startup performance issue #315

Closed yavorfingarov closed 1 year ago

yavorfingarov commented 1 year ago

Hello!

I ran some benchmarks and got surprising results about the startup performance of Carter. Here is the data: https://github.com/yavorfingarov/Reprise#startup

It might be worth to consider this for a future improvement. If you think that there might be a problem with my benchmarks (https://github.com/yavorfingarov/Reprise/tree/master/tests), please let me know.

jchannon commented 1 year ago

Do you have a breakdown of where the time is taken? My guess is Carter assembly scanning and registering types.

On Mon, 19 Dec 2022 at 18:56, Yavor Fingarov @.***> wrote:

Hello!

I ran some benchmarks and got surprising results about the startup performance of Carter. Here is the data: https://github.com/yavorfingarov/Reprise#startup

It might be worth to consider this for a future improvement. If you think that there might be a problem with my benchmarks ( https://github.com/yavorfingarov/Reprise/tree/master/tests), please let me know.

— Reply to this email directly, view it on GitHub https://github.com/CarterCommunity/Carter/issues/315, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAZVJVBVVVVWXLWX6F73ITWOCVURANCNFSM6AAAAAATDVVYZE . You are receiving this because you are subscribed to this thread.Message ID: @.***>

yavorfingarov commented 1 year ago

Thanks for pointing me to the problem!

Reprise and FastEndpoints do an assembly scan too, but Carter scans referenced assemblies as well, so in my case it does considerably more work that the others. I fixed the issue and, as I initially expected, Carter has only a tiny bit slower startup than the Minimal APIs. You can check the updated benchmarks here:

https://github.com/yavorfingarov/Reprise#startup

jchannon commented 1 year ago

You can possibly speed it up more by manually specifying what module to register and what assembly to scan in the AddCarter call

On Tue, 20 Dec 2022 at 19:29, Yavor Fingarov @.***> wrote:

Closed #315 https://github.com/CarterCommunity/Carter/issues/315 as completed.

— Reply to this email directly, view it on GitHub https://github.com/CarterCommunity/Carter/issues/315#event-8081255336, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAZVJSKIYJFVUJADVN4OP3WOICLBANCNFSM6AAAAAATDVVYZE . You are receiving this because you commented.Message ID: @.***>

yavorfingarov commented 1 year ago

Yeah, I did exactly that, thanks.

jchannon commented 1 year ago

Just looked. I reckon you could speed it up a tiny bit more too by specifying the module and validator and exclude response negotiators in the second arg to AddCarter.

Will try a PR tomorrow if I remember.

On Tue, 20 Dec 2022 at 20:17, Yavor Fingarov @.***> wrote:

Yeah, I did exactly that, thanks.

— Reply to this email directly, view it on GitHub https://github.com/CarterCommunity/Carter/issues/315#issuecomment-1360114785, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAZVJXTAFHQ2OEECR2BBT3WOIH5XANCNFSM6AAAAAATDVVYZE . You are receiving this because you commented.Message ID: @.***>

yavorfingarov commented 1 year ago

Thanks for pointing that out! I will exclude the negotiators in the next release. Since both Reprise and FastEndpoints are doing a scan for endpoints and validators, I think specifying those in the Carter implementation might be a bit unfair. Please correct me if I'm wrong.