﻿
{"id":26512,"date":"2023-09-10T10:52:23","date_gmt":"2023-09-10T10:52:23","guid":{"rendered":"https:\/\/www.gencayyildiz.com\/blog\/?p=26512"},"modified":"2023-09-10T10:52:23","modified_gmt":"2023-09-10T10:52:23","slug":"net-8-minimal-api-ahead-of-timeaot-compilation-template","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/net-8-minimal-api-ahead-of-timeaot-compilation-template\/","title":{"rendered":".NET 8 &#8211; Minimal API Ahead of Time(AOT) Compilation Template"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>Bu i\u00e7eri\u011fimizde .NET 8&#8217;de, Asp.NET ekibi taraf\u0131ndan \u00fczerinde \u00e7al\u0131\u015f\u0131lmakta olan ana \u00f6zelliklerden biri olan <em>Ahead of Time(AOT)<\/em> compilation \u00fczerine odaklan\u0131yor olacak ve bu kavram\u0131n ne oldu\u011funu anlayabilmek i\u00e7in \u00f6ncelikle .NET&#8217;te i\u015flerin genel olarak nas\u0131l gitti\u011fine ve AOT ile bu s\u00fcrecin nas\u0131l farkl\u0131la\u015ft\u0131\u011f\u0131na g\u00f6z at\u0131yor olaca\u011f\u0131z.<\/p>\n<p>\u015eimdi her \u015feyden \u00f6nce yaz\u0131 s\u00fcrecinde kullanaca\u011f\u0131m\u0131z baz\u0131 terminolojilere hakimiyet kazanabilmek i\u00e7in a\u015fa\u011f\u0131daki a\u00e7\u0131klama sat\u0131rlar\u0131na g\u00f6z gezdirerek mevzuya giri\u015f yapal\u0131m.<\/p>\n<blockquote><p>\n<em style=\"color:green;\">IL, .NET platformunda kullan\u0131lan ve ara dil(intermediate language) olarak nitelendirilen bir konsepttir ve C#, Visual Basic, F# vs. gibi \u00e7e\u015fitli dillerde yaz\u0131lan programlar\u0131n \u00e7al\u0131\u015ft\u0131r\u0131labilmesini sa\u011flamaktad\u0131r. Programc\u0131lar taraf\u0131ndan bu dillerde yaz\u0131lan kodlar derlendikten sonra insanlar taraf\u0131ndan okunmas\u0131 olduk\u00e7a zor olan, d\u00fc\u015f\u00fck seviyeli bir dil olan CIL(Common Intermediate Language) ad\u0131 verilen ara dile \u00e7evrilirler. CIL dilindeki kodlar ise daha sonraki s\u00fcre\u00e7te Just-In-Time(JIT) derleyicisi taraf\u0131ndan hedef platformun makine koduna \u00e7evrilmektedirler. Bu sayede .NET programlar\u0131 farkl\u0131 platformlarda \u00e7al\u0131\u015ft\u0131r\u0131labilmektedirler.<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-AOT-Compilation-Template.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-AOT-Compilation-Template.jpg\" alt=\".NET 8 - Minimal API AOT Compilation Template\" width=\"603\" height=\"114\" class=\"aligncenter size-full wp-image-26517\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-AOT-Compilation-Template.jpg 603w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-AOT-Compilation-Template-300x57.jpg 300w\" sizes=\"auto, (max-width: 603px) 100vw, 603px\" \/><\/a><br \/>\n<\/em>\n<\/p><\/blockquote>\n<p>\u015eimdi bu bilgiler e\u015fli\u011finde ilk olarak a\u015fa\u011f\u0131daki kodu ele alarak ba\u015flayal\u0131m;<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nclass Program\r\n{\r\n    public static void Main(string&#x5B;] args)\r\n        =&gt; Console.WriteLine(&quot;Naapt\u0131n m\u00fcd\u00fcr?&quot;);\r\n}\r\n<\/pre>\n<\/div>\n<p>Bu kod, derleyici taraf\u0131ndan i\u015flendikten sonra a\u015fa\u011f\u0131dakine benzer bir IL \u00e7\u0131kt\u0131s\u0131 \u00fcretecektir.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n.class private auto ansi beforefieldinit Program\r\n    extends &#x5B;System.Runtime]System.Object\r\n{\r\n    \/\/ Methods\r\n    .method public hidebysig static \r\n        void Main (\r\n            string&#x5B;] args\r\n        ) cil managed \r\n    {\r\n        .custom instance void System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = (\r\n            01 00 01 00 00\r\n        )\r\n        \/\/ Method begins at RVA 0x209d\r\n        \/\/ Code size 11 (0xb)\r\n        .maxstack 8\r\n\r\n        IL_0000: ldstr &quot;Naapt\u0131n m\u00fcd\u00fcr?&quot;\r\n        IL_0005: call void &#x5B;System.Console]System.Console::WriteLine(string)\r\n        IL_000a: ret\r\n    } \/\/ end of method Program::Main\r\n\r\n    .method public hidebysig specialname rtspecialname \r\n        instance void .ctor () cil managed \r\n    {\r\n        \/\/ Method begins at RVA 0x20a9\r\n        \/\/ Code size 7 (0x7)\r\n        .maxstack 8\r\n\r\n        IL_0000: ldarg.0\r\n        IL_0001: call instance void &#x5B;System.Runtime]System.Object::.ctor()\r\n        IL_0006: ret\r\n    } \/\/ end of method Program::.ctor\r\n\r\n} \/\/ end of class Program\r\n<\/pre>\n<\/div>\n<p>Burada g\u00f6r\u00fclen ayr\u0131nt\u0131lar\u0131n bir\u00e7o\u011fu \u00f6nemli de\u011fildir. Bizlerin esas odaklanaca\u011f\u0131 nokta IL&#8217;in hala nispeten y\u00fcksek seviyede \u00e7\u0131kt\u0131 \u00fcretmesidir. Bu talimatlar\u0131 al\u0131p, do\u011frudan CPU \u00fczerinde \u00e7al\u0131\u015ft\u0131ramazs\u0131n\u0131z. Ee haliyle bu durumda IL \u00e7\u0131kt\u0131s\u0131n\u0131 assembly koduna d\u00f6n\u00fc\u015ft\u00fcrebilmek i\u00e7in ba\u015fka bir derleme a\u015famas\u0131na ihtiyac\u0131m\u0131z vard\u0131r. Bunun i\u00e7in de .NET&#8217;te JIT compiler varl\u0131k g\u00f6stermektedir.<\/p>\n<p>JIT ile kodu derledi\u011fimizde ortaya a\u015fa\u011f\u0131daki talimatlara benzer sonu\u00e7lar \u00e7\u0131kmaktad\u0131r;<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n; Core CLR 7.0.823.31807 on x86\r\n\r\nProgram..ctor()\r\n    L0000: ret\r\n\r\nProgram.Main(System.String&#x5B;])\r\n    L0000: mov ecx, &#x5B;0x8fcbf80]\r\n    L0006: call dword ptr &#x5B;0x10d377e0]\r\n    L000c: ret\r\n\r\nMicrosoft.CodeAnalysis.EmbeddedAttribute..ctor()\r\n    L0000: ret\r\n\r\nSystem.Runtime.CompilerServices.NullableAttribute..ctor(Byte)\r\n    L0000: push esi\r\n    L0001: push ebx\r\n    L0002: mov esi, ecx\r\n    L0004: mov ebx, edx\r\n    L0006: mov ecx, 0xa13cabc\r\n    L000b: mov edx, 1\r\n    L0010: call 0x063b319c\r\n    L0015: mov &#x5B;eax+8], bl\r\n    L0018: lea edx, &#x5B;esi+4]\r\n    L001b: call 0x06380008\r\n    L0020: pop ebx\r\n    L0021: pop esi\r\n    L0022: ret\r\n\r\nSystem.Runtime.CompilerServices.NullableAttribute..ctor(Byte&#x5B;])\r\n    L0000: mov eax, edx\r\n    L0002: lea edx, &#x5B;ecx+4]\r\n    L0005: call 0x06380008\r\n    L000a: ret\r\n\r\nSystem.Runtime.CompilerServices.NullableContextAttribute..ctor(Byte)\r\n    L0000: mov &#x5B;ecx+4], dl\r\n    L0003: ret\r\n\r\nSystem.Runtime.CompilerServices.RefSafetyRulesAttribute..ctor(Int32)\r\n    L0000: mov &#x5B;ecx+4], edx\r\n    L0003: ret\r\n\r\n<\/pre>\n<\/div>\n<p>\u0130\u015fte bunlar CPU taraf\u0131ndan ger\u00e7ekten \u00e7al\u0131\u015ft\u0131r\u0131labilir talimatlard\u0131r.<\/p>\n<p>\u015eimdi d\u00fc\u015f\u00fcn\u00fcrsek e\u011fer, madem ki nihai olarak kodu bizim JIT \u00e7\u0131kt\u0131s\u0131na d\u00f6n\u00fc\u015ft\u00fcrmemiz gerekmektedir, o halde neden \u00f6nce IL \u00e7\u0131kt\u0131s\u0131na d\u00f6n\u00fc\u015ft\u00fcr\u00fcp, zaman kaybediyoruz ki? Direkt JIT \u00e7\u0131kt\u0131s\u0131n\u0131 hedeflesek derleme a\u00e7\u0131s\u0131ndan daha az maliyetli bir s\u00fcre\u00e7 s\u00f6z konusu olmayacak m\u0131? Olur gibi de\u011fil mi&#8230;<\/p>\n<p>\u0130\u015fte AOT derlemesi sayesinde ara IL derleme ad\u0131m\u0131n\u0131 tamamen atlayabilir ve do\u011frudan kodu CPU&#8217;da \u00e7al\u0131\u015fabilecek assembly koduna d\u00f6n\u00fc\u015ft\u00fcrebiliriz. Tabi \u00f6ncelikle bunun nas\u0131l yap\u0131ld\u0131\u011f\u0131ndan \u00f6te, derleme s\u00fcrecindeki bu do\u011fal ak\u0131mda neden AOT&#8217;ye nazaran JIT&#8217;in tercih edildi\u011fini ve AOT ile JIT aras\u0131ndaki avantaj ve dezavantaj durumlar\u0131n\u0131 de\u011ferlendirerek konumuza devam etmekte fayda g\u00f6rmekteyim. <\/p>\n<h3>AOT Compilation &#8211; Avantaj ve Dezavantajlar\u0131<\/h3>\n<p>Ahead of Time(AOT); .NET platformunda, runtime&#8217;da uygulama kodunun JIT taraf\u0131ndan derlenmesi yerine bu i\u015flemin \u00f6nceden yap\u0131larak uygulama performans\u0131n\u0131 art\u0131rmak i\u00e7in kullan\u0131lan bir tekniktir. JIT derlemesi, uygulaman\u0131n ba\u015flat\u0131lma ve \u00e7al\u0131\u015ft\u0131rma s\u00fcrelerinde ister istemez gecikmelere sebebiyet verebilmektedir. \u0130\u015fte bizler bu gecikmelere kar\u015f\u0131n AOT derleme ile kodun \u00f6nceden derlenmesini sa\u011flayarak gecikmeleri minimize edebilmekte ve uygulaman\u0131n daha h\u0131zl\u0131 ba\u015flat\u0131lmas\u0131n\u0131 sa\u011flayabilmekteyiz.<\/p>\n<p>Evet, akl\u0131n\u0131za gelebilece\u011fi \u00fczere yaln\u0131zca bir kez ba\u015flat\u0131lan ve bunun \u00fczerine saatlerce ve hatta g\u00fcnlerce \u00e7al\u0131\u015fan geleneksel sunucu uygulamalar\u0131nda ba\u015flatma s\u00fcresinin uzun olmas\u0131 pek \u00f6nem te\u015fkil etmeyecektir. Ancak <a href=\"https:\/\/www.gencayyildiz.com\/blog\/aws-lambda-ile-serverless-rest-api-gelistirme-asp-net-core-api\/\" rel=\"noopener\" target=\"_blank\">AWS Lambda<\/a> veya <a href=\"https:\/\/www.gencayyildiz.com\/blog\/azure-functions-yazi-serisi\/\" rel=\"noopener\" target=\"_blank\">Azure Function<\/a> gibi cloud teknolojilerden istifade eden uygulamalarda ise ba\u015flatma s\u00fcresi olduk\u00e7a \u00f6nem arz etmektedir.<\/p>\n<p>Bu platformlardaki uygulamalar her daim ayakta tutulmamaktad\u0131rlar, bilakis ilk gelen iste\u011fe kar\u015f\u0131n function&#8217;\u0131n kullan\u0131labilirli\u011fini haz\u0131r duruma getirmek i\u00e7in gerekli \u00f6n y\u00fcklemeler y\u00fcr\u00fct\u00fclmekte ve akabinde function ba\u015flat\u0131larak, i\u015flevlerini ger\u00e7ekle\u015ftirmeye odaklan\u0131lmaktad\u0131r. Sonras\u0131nda ise belirli bir m\u00fcddet istek gelmedi\u011fi taktirde function tekrardan so\u011fuyacak ve bir sonraki gelen ilk istekte bu s\u00fcre\u00e7 ba\u015ftan tekrar ediyor olacakt\u0131r. Ee do\u011fal olarak bu tarz uygulamalarda ba\u015flatma s\u00fcresi olduk\u00e7a \u00f6nemli bir parametre olmaktad\u0131rlar.<\/p>\n<p>\u0130\u015fte bu tarz senaryolara kar\u015f\u0131n AOT derlemesi bi\u00e7ilmi\u015f kaftand\u0131r diyebiliriz. Cloud teknolojilerinin yayg\u0131nla\u015fmas\u0131 ve yap\u0131sal olarak yukar\u0131da bahsedilen ortamlarda ba\u015flang\u0131\u00e7 zamanlar\u0131n\u0131n kritik bir parametre olarak kar\u015f\u0131m\u0131za \u00e7\u0131kmas\u0131, .NET 8&#8217;de AOT derlemesinin odak noktas\u0131 olmas\u0131na sebebiyet do\u011furmu\u015ftur diye d\u00fc\u015f\u00fcnebiliriz. Ancak buradaki g\u00fczellemeler neticesinde AOT&#8217;nin her daim JIT derlemesinden daha iyi oldu\u011fu kanaatine varmamak gerekmektedir. Yerinde kullan\u0131lmad\u0131\u011f\u0131 taktirde pek \u00e7ok dezavantaj durumu da s\u00f6z konusu olabilmektedir.<\/p>\n<p>AOT&#8217;nin ana sorunlar\u0131ndan biri, makine kodunun IL&#8217;den \u00fcretilmi\u015f olana nazaran \u00f6nemli \u00f6l\u00e7\u00fcde daha b\u00fcy\u00fck olmas\u0131d\u0131r. Haliyle bir Asp.NET Core uygulamas\u0131n\u0131 AOT ile derlerseniz, \u00fcretilecek dosyalar\u0131n ortaya \u00e7\u0131kacak boyutu kesinlikle IL&#8217;dekine oranla \u00e7ok daha b\u00fcy\u00fck olacakt\u0131r.<\/p>\n<p>Bir di\u011fer sorun ise AOT&#8217;nin direkt olarak Widows x64 veya Linux arm64 gibi belirli bir platform i\u00e7in assembly kodu olu\u015fturmas\u0131d\u0131r. Bu durumda da, IL&#8217;in platformlar aras\u0131 davran\u0131\u015f\u0131na kar\u015f\u0131n yaln\u0131zca belirtilen platformda \u00e7al\u0131\u015fma s\u0131n\u0131rl\u0131l\u0131\u011f\u0131 s\u00f6z konusu olacakt\u0131r.<\/p>\n<p>T\u00fcm bunlar\u0131n d\u0131\u015f\u0131nda, JIT derleyicisinin, kodun \u00fczerinde \u00e7al\u0131\u015ft\u0131\u011f\u0131 makine hakk\u0131nda AOT derleyicisinden daha fazla bilgi sahibi olabilmesi de, potansiyel olarak JIT&#8217;in, AOT derleyicisinden daha fazla optimize edilmi\u015f kod \u00fcretebilece\u011fi anlam\u0131na gelecektir ve i\u015fte bu da, kimi zamanlarda JIT&#8217;in performans\u0131n\u0131n AOT&#8217;den daha iyi olabilece\u011fini g\u00f6stermektedir.<\/p>\n<p>Olay\u0131 teorik olarak bu \u015fekilde yorumlad\u0131ktan sonra k\u0131saca \u00f6zetlememiz gerekirse e\u011fer;<\/p>\n<table style=\"font-size:12px;\">\n<thead>\n<tr>\n<th width=\"20%\"><\/th>\n<th width=\"40%\">Avantajlar<\/th>\n<th width=\"40%\">Dezavantajlar<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align:left;\"><strong>AOT Compilation<\/strong><\/td>\n<td style=\"text-align:left;vertical-align: top;\">\n<ul>\n<li><strong><em>Ba\u015flatma H\u0131z\u0131<\/em><\/strong><br \/>\nAOT derlemesi neticesinde kod zaten hali haz\u0131rda derlenmi\u015f olaca\u011f\u0131 i\u00e7in uygulaman\u0131n ba\u015flatma h\u0131z\u0131n\u0131 art\u0131rabilir. JIT derlemesi ise kodun ba\u015flat\u0131lma s\u00fcresini uzatabilir, \u00e7\u00fcnk\u00fc kodun bir k\u0131sm\u0131 \u00e7al\u0131\u015fma an\u0131nda derlenmektedir.\n<\/li>\n<li><strong><em>Daha D\u00fc\u015f\u00fck Bellek Kullan\u0131m\u0131<\/em><\/strong><br \/>\nAOT derlemesi, \u00f6nceden derlenmi\u015f kod nedeniyle daha d\u00fc\u015f\u00fck bellek kullan\u0131m\u0131 sa\u011flayabilmektedir. JIT ise derleme s\u0131ras\u0131nda ve runtime&#8217;da bellek kullan\u0131m\u0131n\u0131 bazen istemsiz art\u0131rabilmektedir.\n<\/li>\n<li><strong><em>G\u00fcvenlik<\/em><\/strong><br \/>\nAOT derlemesi sayesinde kaynak ve ara kodun a\u00e7\u0131k\u00e7a sunulmas\u0131 gerekmeyece\u011finden uygulaman\u0131n kod seviyesinde daha iyi korunmas\u0131 s\u00f6z konusu olabilmektedir.\n<\/li>\n<\/ul>\n<\/td>\n<td style=\"text-align:left;vertical-align: top;\">\n<ul>\n<li><strong><em>B\u00fcy\u00fcme<\/em><\/strong><br \/>\nAOT derlemesi, platforma \u00f6zg\u00fc kod \u00fcretti\u011fi i\u00e7in uygulaman\u0131n boyutunu art\u0131rabilir. \u00d6zellikle bu durum, mobil cihazlar ve s\u0131n\u0131rl\u0131 depolama alan\u0131na sahip cihazlar i\u00e7in dezavantaj olabilir.\n<\/li>\n<li><strong><em>G\u00fcncelleme Zorlu\u011fu<\/em><\/strong><br \/>\nAOT derlemesi, uygulama g\u00fcncellemelerini daha zor ve karma\u015f\u0131k hale getirebilir, \u00e7\u00fcnk\u00fc yaz\u0131l\u0131m s\u00fcrecinde s\u00fcrekli olarak kodun yeniden derlenmesi ve uygulaman\u0131n yeniden deploy edilmesi i\u015fin do\u011fas\u0131nda vard\u0131r. JIT derlemesi bu a\u00e7\u0131dan daha esnek olabilmektedir.\n<\/li>\n<li><strong><em>Ba\u011f\u0131ml\u0131l\u0131klar<\/em><\/strong><br \/>\nAOT derlemesinde, uygulaman\u0131n \u00e7al\u0131\u015fabilmesi i\u00e7in t\u00fcm ba\u011f\u0131ml\u0131l\u0131klar\u0131n \u00f6nceden derlenmi\u015f olmas\u0131 gerekir. Bu durum, ba\u011f\u0131ml\u0131l\u0131klar\u0131n g\u00fcncellenmesinin daha karma\u015f\u0131k hale gelebilece\u011fi anlam\u0131na gelebilir.\n<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left;\"><strong>JIT Compilation<\/strong><\/td>\n<td style=\"text-align:left;vertical-align: top;\">\n<ul>\n<li><strong><em>Kod Boyutu<\/em><\/strong><br \/>\nJIT derlemesi, genellikle AOT&#8217;ye nazaran daha k\u00fc\u00e7\u00fck uygulama boyutlar\u0131na yol a\u00e7maktad\u0131r. Bu da maliyet a\u00e7\u0131s\u0131ndan daha avantajl\u0131 bir durum olarak de\u011ferlendirilebilir.\n<\/li>\n<li><strong><em>Dinamik Optimizasyon<\/em><\/strong><br \/>\nJIT derlemesi, \u00e7al\u0131\u015fma s\u0131ras\u0131nda platform \u00f6zelliklerine ve kullan\u0131m desenlerine g\u00f6re kodu AOT&#8217;ye nazaran daha iyi optimize edebilir.\n<\/li>\n<li><strong><em>G\u00fcncelleme Kolayl\u0131\u011f\u0131<\/em><\/strong><br \/>\nJIT derlemesi, uygulamada sadece de\u011fi\u015fen k\u0131s\u0131mlar\u0131n yeniden derlenmesini sa\u011flayarak s\u00fcre\u00e7teki g\u00fcncellemeleri daha esnek hale getirebilir.\n<\/ul>\n<\/td>\n<td style=\"text-align:left;vertical-align: top;\">\n<ul>\n<li><strong><em>Ba\u015flatma H\u0131z\u0131<\/em><\/strong><br \/>\nJIT derlemesi, derleme s\u00fcresini \u00e7al\u0131\u015fma an\u0131nda ger\u00e7ekle\u015ftirece\u011fi i\u00e7in uygulaman\u0131n ba\u015flat\u0131lma s\u00fcresini uzatabilir.\n<\/li>\n<li><strong><em>Bellek Kullan\u0131m\u0131<\/em><\/strong><br \/>\nJIT derlemesinde hem kaynak hem de derlenmi\u015f kod bellekte tutulaca\u011f\u0131 i\u00e7in AOT&#8217;ye nazaran, runtime&#8217;da daha fazla bellek kullan\u0131m durumu s\u00f6z konusu olabilir..\n<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Muhtemelen t\u00fcm bu anlat\u0131lanlar\u0131n .NET 8&#8217;de gelebilecek olan hangi yenilikle ne gibi bir ili\u015fkisi olabilece\u011fini merak ediyorsunuz. Evet, hak veriyorum. O halde fazla sabr\u0131n\u0131z\u0131 s\u0131namadan .NET 8&#8217;deki sadede gelelim.<\/p>\n<h3>.NET 8&#8217;de AOT Template&#8217;i<\/h3>\n<p>.NET 8&#8217;de, AOT ile haz\u0131r derlenme temelinde sunulan Minimal bir API projesi template&#8217;i gelmektedir. Bu template, birazdan da g\u00f6rece\u011fimiz \u00fczere basit bir endpoint konfig\u00fcrasyon i\u00e7eri\u011fine sahiptir.<\/p>\n<p>AOT template&#8217;inde bir uygulama olu\u015fturmak istiyorsan\u0131z dotnet cli \u00fczerinden<br \/>\n<code style=\"color:green;\"><strong>dotnet new webapiaot --name &lt;project name&gt;<\/strong><\/code> \u015feklinde talimat\u0131n\u0131z\u0131 verebilirsiniz.<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template.png\" alt=\".NET 8 - Minimal API Ahead of Time(AOT) Compilation Template\" width=\"834\" height=\"100\" class=\"aligncenter size-full wp-image-26520\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template.png 834w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template-300x36.png 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template-768x92.png 768w\" sizes=\"auto, (max-width: 834px) 100vw, 834px\" \/><\/a>Ya da Visual Studio \u015fablonlar\u0131ndan da a\u015fa\u011f\u0131daki gibi &#8216;native AOT&#8217; olan template&#8217;i se\u00e7ip, proje olu\u015fturabilirsiniz.<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template-1.png\" alt=\".NET 8 - Minimal API Ahead of Time(AOT) Compilation Template\" width=\"890\" height=\"184\" class=\"aligncenter size-full wp-image-26522\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template-1.png 890w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template-1-300x62.png 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template-1-768x159.png 768w\" sizes=\"auto, (max-width: 890px) 100vw, 890px\" \/><\/a><a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template-2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template-2.png\" alt=\".NET 8 - Minimal API Ahead of Time(AOT) Compilation Template\" width=\"211\" height=\"154\" class=\"alignleft size-full wp-image-26523\" \/><\/a>\u015eimdi bu template&#8217;te olu\u015fturulan bir uygulamaya g\u00f6z att\u0131\u011f\u0131m\u0131zda soldaki gibi bir dosya yap\u0131lanmas\u0131na sahip olacakt\u0131r.<\/p>\n<p>Direkt &#8216;Program.cs&#8217; dosyas\u0131n\u0131 incelersek e\u011fer a\u015fa\u011f\u0131daki gibi bir i\u00e7erikle bizleri kar\u015f\u0131layacakt\u0131r;<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nusing System.Text.Json.Serialization;\r\n\r\nvar builder = WebApplication.CreateSlimBuilder(args);\r\n\r\nbuilder.Services.ConfigureHttpJsonOptions(options =&gt;\r\n{\r\n    options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);\r\n});\r\n\r\nvar app = builder.Build();\r\n\r\nvar sampleTodos = new Todo&#x5B;] {\r\n    new(1, &quot;Walk the dog&quot;),\r\n    new(2, &quot;Do the dishes&quot;, DateOnly.FromDateTime(DateTime.Now)),\r\n    new(3, &quot;Do the laundry&quot;, DateOnly.FromDateTime(DateTime.Now.AddDays(1))),\r\n    new(4, &quot;Clean the bathroom&quot;),\r\n    new(5, &quot;Clean the car&quot;, DateOnly.FromDateTime(DateTime.Now.AddDays(2)))\r\n};\r\n\r\nvar todosApi = app.MapGroup(&quot;\/todos&quot;);\r\ntodosApi.MapGet(&quot;\/&quot;, () =&gt; sampleTodos);\r\ntodosApi.MapGet(&quot;\/{id}&quot;, (int id) =&gt;\r\n    sampleTodos.FirstOrDefault(a =&gt; a.Id == id) is { } todo\r\n        ? Results.Ok(todo)\r\n        : Results.NotFound());\r\n\r\napp.Run();\r\n\r\npublic record Todo(int Id, string? Title, DateOnly? DueBy = null, bool IsComplete = false);\r\n\r\n&#x5B;JsonSerializable(typeof(Todo&#x5B;]))]\r\ninternal partial class AppJsonSerializerContext : JsonSerializerContext\r\n{\r\n\r\n}\r\n<\/pre>\n<\/div>\n<p>\u015eimdi buradaki kod blo\u011funu incelersek e\u011fer birka\u00e7 ilgin\u00e7 noktayla kar\u015f\u0131la\u015fmaktay\u0131z.<\/p>\n<p>Bunlardan ilki, <strong><em>3.<\/em><\/strong> sat\u0131rda bir sonraki i\u00e7eri\u011fimizde derinlemesine incelemede bulunaca\u011f\u0131m\u0131z <code>CreateBuilder<\/code> fonksiyonu yerine gelen <code>CreateSlimBuilder<\/code> fonksiyonunun kullan\u0131lmas\u0131d\u0131r.<\/p>\n<p>Bir di\u011fer nokta ise AOT i\u00e7in gerekli olan <em><strong>31<\/strong><\/em> ile <em><strong>35.<\/strong><\/em> sat\u0131r aral\u0131\u011f\u0131nda tan\u0131mlanm\u0131\u015f olan &#8216;JsonSerializerContext&#8217; s\u0131n\u0131f\u0131n\u0131n <em><strong>5<\/strong><\/em> ile <em><strong>8.<\/strong><\/em> sat\u0131r aral\u0131\u011f\u0131nda yap\u0131land\u0131r\u0131lmas\u0131d\u0131r.<\/p>\n<p>Ve son olarak da <em><strong>12<\/strong><\/em> ile <em><strong>18.<\/strong><\/em> sat\u0131r aral\u0131\u011f\u0131nda \u00f6rnek data olmas\u0131 amac\u0131yla abart\u0131l\u0131 bir dizi tan\u0131m\u0131nda bulunulmas\u0131d\u0131r.<\/p>\n<p>Ayr\u0131ca uygulaman\u0131n <code>.csproj<\/code> dosyas\u0131na g\u00f6z atarsak e\u011fer;<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;Project Sdk=&quot;Microsoft.NET.Sdk.Web&quot;&gt;\r\n\r\n  &lt;PropertyGroup&gt;\r\n    &lt;TargetFramework&gt;net8.0&lt;\/TargetFramework&gt;\r\n    &lt;Nullable&gt;enable&lt;\/Nullable&gt;\r\n    &lt;ImplicitUsings&gt;enable&lt;\/ImplicitUsings&gt;\r\n    &lt;RootNamespace&gt;Company.WebApplication1&lt;\/RootNamespace&gt;\r\n    &lt;InvariantGlobalization&gt;true&lt;\/InvariantGlobalization&gt;\r\n    &lt;PublishAot&gt;true&lt;\/PublishAot&gt;\r\n  &lt;\/PropertyGroup&gt;\r\n\r\n&lt;\/Project&gt;\r\n<\/pre>\n<\/div>\n<p>\u015feklinde oldu\u011funu g\u00f6zlemliyoruz. Burada dikkat edilmesi gereken esas hususun <em><strong>10.<\/strong><\/em> sat\u0131rdaki <code>&lt;PublishAot&gt;true&lt;\/PublishAot&gt;<\/code> yap\u0131land\u0131rmas\u0131 oldu\u011funa dikkatinizi \u00e7ekerim.<\/p>\n<p>T\u00fcm bunlar\u0131n d\u0131\u015f\u0131nda uygulaman\u0131n endpoint&#8217;lerini h\u0131zl\u0131ca test edebilmemiz i\u00e7in HTTP request&#8217;leriyle yap\u0131land\u0131r\u0131lm\u0131\u015f bir <code>.http<\/code> dosyas\u0131 olan &#8216;example-aot-project.http&#8217; dosyas\u0131n\u0131 da incelersek e\u011fer;<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n@example_aot_project_HostAddress = http:\/\/localhost:5177\r\n\r\nGET {{example_aot_project_HostAddress}}\/todos\/\r\nAccept: application\/json\r\n\r\n###\r\n\r\nGET {{example_aot_project_HostAddress}}\/todos\/1\r\nAccept: application\/json\r\n\r\n###\r\n<\/pre>\n<\/div>\n<p>\u015feklinde bir i\u00e7erikle kar\u015f\u0131m\u0131za \u00e7\u0131kmaktad\u0131r. Bu dosyan\u0131n kullan\u0131m\u0131 a\u015fa\u011f\u0131daki g\u00f6rseldeki gibi netice vermektedir.<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template-3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template-3.png\" alt=\".NET 8 - Minimal API Ahead of Time(AOT) Compilation Template\" width=\"1467\" height=\"510\" class=\"alignleft size-full wp-image-26525\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template-3.png 1467w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template-3-300x104.png 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template-3-1024x356.png 1024w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template-3-768x267.png 768w\" sizes=\"auto, (max-width: 1467px) 100vw, 1467px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template-4.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template-4.png\" alt=\".NET 8 - Minimal API Ahead of Time(AOT) Compilation Template\" width=\"302\" height=\"368\" class=\"alignleft size-full wp-image-26526\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template-4.png 302w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/09\/NET-8-Minimal-API-Ahead-of-TimeAOT-Compilation-Template-4-246x300.png 246w\" sizes=\"auto, (max-width: 302px) 100vw, 302px\" \/><\/a>\u015eimdi t\u00fcm bu haz\u0131r konfig\u00fcrasyonlarla uygulamay\u0131 test etmek i\u00e7in derleyip, \u00e7al\u0131\u015ft\u0131r\u0131rsak e\u011fer direkt taray\u0131c\u0131 \u00fczerinden response&#8217;un soldaki ekran g\u00f6r\u00fcnt\u00fcs\u00fcnde oldu\u011fu gibi geldi\u011fini g\u00f6rebilmekteyiz.<\/p>\n<p>Sizler JIT ile derlenmi\u015f olan bu uygulaman\u0131n muadili bir i\u00e7eri\u011fe sahip ba\u015fka bir Asp.NET Core uygulamas\u0131n\u0131, buradaki a\u00e7\u0131l\u0131\u015f h\u0131z\u0131yla k\u0131yaslayabilir ve gerekli \u00f6l\u00e7\u00fcmleri yapabilirsiniz. \u0130nternette yapt\u0131\u011f\u0131m ara\u015ft\u0131rmalar sonucu bu kar\u015f\u0131la\u015ft\u0131rmay\u0131 yapanlarda nereden baksan\u0131z ba\u015flang\u0131\u00e7 s\u00fcresinde 1\/8 oran\u0131na yak\u0131n art\u0131\u015f g\u00f6zlemlendi\u011fi s\u00f6ylenmektedir.<\/p>\n<p>\u0130\u015fte yerinde kullan\u0131ld\u0131\u011f\u0131nda AOT&#8217;nin g\u00fcc\u00fc bu \u015fekilde tezah\u00fcr edecektir \ud83d\ude42<\/p>\n<p>Nihai olarak;<br \/>\n\u0130\u00e7erik boyunca AOT ile JIT derlemeleri aras\u0131ndaki mukayeseyi ger\u00e7ekle\u015ftirerek, .NET 8 ile Microsoft&#8217;un gelece\u011fe yine performans odakl\u0131 bir misyon besledi\u011fini g\u00f6rm\u00fc\u015f bulunuyoruz. Tabi ki de bir \u00e7i\u00e7ekle bahar olmayaca\u011f\u0131 gibi salt AOT ile yap\u0131lan derlemelerinde mutlak performans getirmeyece\u011fini, uygun olmayan durumlarda ise ekstradan maliyetlere sebebiyet verebilece\u011fini de de\u011ferlendirmi\u015f bulunuyoruz. \u00d6zellikle gelen bu yenili\u011fin, AWS Lambda ve Azure Function gibi \u00e7a\u011fda\u015f cloud \u00e7\u00f6z\u00fcmlere odakland\u0131\u011f\u0131m\u0131z \u00e7al\u0131\u015fmalar da AOT derlemesinin finansal a\u00e7\u0131s\u0131ndan bizlere ne kadar avantaj sa\u011flayabilece\u011fine dair de bir vizyon temeli sa\u011flayabilece\u011fini d\u00fc\u015f\u00fcn\u00fcyoruz.<\/p>\n<p>O halde hay\u0131rl\u0131 olsun diyelim \ud83d\ude42<\/p>\n<p>\u0130lgilenenlerin faydalanmas\u0131 dile\u011fiyle&#8230;<br \/>\nSonraki yaz\u0131lar\u0131mda g\u00f6r\u00fc\u015fmek \u00fczere&#8230;<br \/>\n\u0130yi \u00e7al\u0131\u015fmalar&#8230;<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Merhaba, Bu i\u00e7eri\u011fimizde .NET 8&#8217;de, Asp.NET ekibi taraf\u0131ndan \u00fczerinde \u00e7al\u0131\u015f\u0131lmakta olan ana \u00f6zelliklerden biri olan Ahead of Time(AOT) compilation \u00fczerine odaklan\u0131yor olacak ve bu kavram\u0131n ne oldu\u011funu anlayabilmek i\u00e7in \u00f6ncelikle .NET&#8217;te i\u015flerin genel olarak&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":26528,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4912],"tags":[4915,4922,4920,4928,4913,4916,4914,4917,4923,4921,4929,381,4919,4918,4925,4926,4924,4927],"class_list":["post-26512","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-net-8","tag-net-8","tag-net-cil-nedir","tag-net-il-nedir","tag-net-jit-nedir","tag-ahead-of-time","tag-ahead-of-time-compilation","tag-aot","tag-aot-compilation","tag-cil","tag-common-intermediate-language","tag-createslimbuilder","tag-il","tag-il-nedir","tag-intermediate-language","tag-jit","tag-jit-nedir","tag-just-in-time","tag-just-in-time-nedir"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/26512","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/comments?post=26512"}],"version-history":[{"count":8,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/26512\/revisions"}],"predecessor-version":[{"id":26529,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/26512\/revisions\/26529"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/26528"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=26512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=26512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=26512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}