Wow i never expected this in C#. Really cool! I didn't read the article, but i assume it works by fully stripping out the entire runtime and unused functions. Because the game itself just calls pure system functions from the win32 api stack and does not use the GC. Also the win32 libraries that are used (kernel32 and user32) are not statically linked, instead it is runtime linked - meaning LoadLibrary() and GetProcAddress() is used. Btw. these techniques are well known in the demo-scene and used in languages such as C and object pascal. For example there was a fully working C64 emulator (Brotkästchen) written in borland delphi 5 that compiles to an executable with just 64 KB.
@@shahzaibhassan2777 Static Linking effectively means that whatever you linked will be inside of your final output, as opposed to dynamic linking where your libraries will be linked during startup. Embedded as in contained in your final exe/dll.
This was super interesting and I'm glad the algorithm recommended it. I was a C# dev for about 8 or 9 years but switched to pretty much straight Node.js for the last 7. Seeing tooling and this sort of thing is making want to come back a bit and see what I can do. I've got enough gripes with JS and its eco system but I see it's benefits. Knowing that you can do this sort of thing with C# is inviting. I'd really want to see how it compares to Go in performance. Might give it a try, just hope it plays well with Linux!
Wow! NO garbage collector! That is one of the points that Bflat mentions. I guess that means that most standard dotnet stuff becomes totally impossible, even Strings. LOL. But an unsafe application that only targets native Win32 stuff should indeed be able to run. Everything completely unmanaged. However, to be honest, I don't think C# is really a serious option anymore here. Here is where I just like Rust a lot more, or even C and C++, because those languages are actually designed for this job. And C# is simply not. As an experimental showcase though, I think this is cool. Rust with a garbage collector would also by nice for one moment. Just to see that it's possible.
**Make Code Small Again** I LOVE this!! Amazing video, Nick. Every year new toolings come out and default sizes only get larger and larger. Long gone are the days of KB sized GUI apps with minimum resource usage. Really hope this makes a come back again.
For this particular project, you say? If it is, I believe that it is very optimized, as the maze game makes full usage of OS API calls and unsafe, self-managed resources. There doesn't seem to be any need for garbage collection at all, in this case.
Yeah, I'd like to know more about the limitations for Bflat... as I have a few apps which call external windows functions, registry, eventlogs, wmi etc... and I have them AOT'd already... but if there's a significant difference in size, that could be interesting
If I'm being honest. My brain is saying two things. The first is "this is really cool" and the second one is "but why?" There are times where just because you can doesn't mean you should. Maybe the Bflat project falls into that or maybe it doesn't. I honestly don't know. It definitely is really neat though.
Look up 4k demos. One I remember is droplets of water, rendered with software raytracing, merging and splitting in real-time (and the program was under 4KB. This C# demo is in some ways more impressive because it is written in a high-level (sort of, looking at the code) language rather than assembly language, and it doesn't use any crazy tricks like fractal data generation. Another was the first level of the Interplay game Descent, including music, the 3D level, and lava animations, in 4k. Another was a terrain generator called "mars", which was, IIRC, about 2.8K, and generated unlimited random Martian terrain (the detail wasn't great, mostly red hills). Still a better plot than most Bethesda games.
Impressive, but in the end i think it more illustrates how the "usual thing" is pretty wasteful and "loose" than anything else. Reason that "trim obvious fat" isn't default is probably because lord knows how much dependency you have on reflection and/or dynamic code creation.
There is also a tradeoff between binary size, memory allocation, startup time and performance. If you optimize towards one of them, you probably loose the others In this case, he compresses the binary, so startup is longer and possibly you might store both versions in ram, at least for some time. The static loading of libraries prohibits you from usibg gac or sharing the same lib between apps. Size optimisation will not expand loops, so you loose performance on branch prediction Everything has its cost
Reminds me of that 64Kb game from a couple years back that was a fully fledged shooter with for the time decent graphics and sound, all in a 64 kilobyte install. Technologically completely different (they used DirectX or openGL to do most of the heavy lifting) but still crazy what can be done with extremely little
While I can definitely agree with more than a few posters that this is insane, I'm also going to argue that this isn't really C# - certainly not by itself IMO. But I can at least agree that everything is being orchestrated in C# but it's just P/Invoking into the native land where all the magic happens. So in that respect C# is almost like a Kubernetes to all of the linked (P/Invoked) Services.
I wish I could create a framework / engine that takes advantage of this and become a Unity competitor. I wouldn't even know where to start and I've been engineering for 14 years in a completely different field of study. I better get on it...
I appreciate that you didn't want us to have a stroke from seeing egregious code XD (btw, I didn't see the code yet, still watching the video) The only thing I am dissapointed by with this video is, not seeing a QR code of the binary exe file :P I hope that is indeed possible.
It takes something sharp and commands it to be flat (the opposite of sharp). I guess it could be called RemovEdge or NoEdge, but that's not allowed at Microsoft.
There's a video from MattKC where he actually put a game into a QR-Code and he also used crinkler. However he could only fit snake into the code. Having a 3d graphics game this small kinda blew me from my chair, not gonna lie.
The zero std lib sais it does not have a garbage collector? So does that mean your game will just memory leak if it ever allocates anything, at any point. I mean I get it for small CLI tools, garbage collection tends to be useless work, because you can just explode the process afterwards. If your total program runtime is a fraction of a second who cares. Is that the intention? Because, I have no idea how I would even deallocate anything in c# by hand. There might be some unsafe black magic.
I started programming way back when hand coding byte sized registers with switches. I have NEVER understood the size bloat that has been with us in the decades since. All we are doing here is returning to what should have been before memory and disk space became so cheap and we did not have to bother doing it right first time. My own view is that a code executable should always be derived from a complete source code that then goes with compiler/linker tooling options right to the metal of the CPU. None of this proprietary library crap.
Interesting how you can make it so small but practically not too useful for me to go all the way down. I think the first suggestion to build "self-contained" is a good option.
I read through Michal's entire blog a few weeks ago when this popped up on Reddit. I'm fairly certain he lives on an island somewhere with a white cat and a giant fish tank full of sharks (possibly with lasers attached to their heads).
This is Michal creator of bflat which rocks podcasts.google.com/feed/aHR0cHM6Ly90aGVkb3RuZXRjb3JlcG9kY2FzdC5saWJzeW4uY29tL3Jzcw/episode/NmI2OWU4NWYtMzcwMS00ZTRmLWI2NGMtZjZmMTI3MjJlZDVk?ep=14
8 หลายเดือนก่อน +1
All game studios should learn this trick, maybe the games will be again available to share via diskettes instead of the size 160GB :D
In modern AAA games most if it's size are 4k videos and 4k textures. Some repackers let you to not download unnecessary things. (I'm still buying games tho, but when I was a student - that was a totally different story... ;-) )
Anyone else who thought about a musical scale after watching this... C sharp, b flat, f sharp, where's the rest of the scale. Joking aside, great video Nick!
i’ve been looking at the possibility of using nanoframework for RP2040… there’s been work to add support but it’s rough going. if we could bring Sdk style project and use a similar stack to this video i think it could solve a lot of issues
This is insane. Please tell us more on bflat and more like this.
Wow i never expected this in C#. Really cool!
I didn't read the article, but i assume it works by fully stripping out the entire runtime and unused functions. Because the game itself just calls pure system functions from the win32 api stack and does not use the GC. Also the win32 libraries that are used (kernel32 and user32) are not statically linked, instead it is runtime linked - meaning LoadLibrary() and GetProcAddress() is used. Btw. these techniques are well known in the demo-scene and used in languages such as C and object pascal. For example there was a fully working C64 emulator (Brotkästchen) written in borland delphi 5 that compiles to an executable with just 64 KB.
Does static linking kinda mean 'Embedded'?
@@shahzaibhassan2777 Yes, the more libraries you statically link, the more larger your executable will become.
@@shahzaibhassan2777 Pretty much, yeah.
@@shahzaibhassan2777 it means code is pasted inside your program
@@shahzaibhassan2777 Static Linking effectively means that whatever you linked will be inside of your final output, as opposed to dynamic linking where your libraries will be linked during startup. Embedded as in contained in your final exe/dll.
I read that article yesterday. Pretty cool that you are doing a video about it, despite its extremely niche use case.
This was super interesting and I'm glad the algorithm recommended it. I was a C# dev for about 8 or 9 years but switched to pretty much straight Node.js for the last 7.
Seeing tooling and this sort of thing is making want to come back a bit and see what I can do. I've got enough gripes with JS and its eco system but I see it's benefits. Knowing that you can do this sort of thing with C# is inviting. I'd really want to see how it compares to Go in performance. Might give it a try, just hope it plays well with Linux!
I just got this article on yesterday's C# Digest but I prefer a 12 min video than a 14 min read lol
IOCCC for C# next? :D
The line between language abuse and optimization is thin.
AWESOME!!
Wow! NO garbage collector! That is one of the points that Bflat mentions. I guess that means that most standard dotnet stuff becomes totally impossible, even Strings. LOL.
But an unsafe application that only targets native Win32 stuff should indeed be able to run. Everything completely unmanaged.
However, to be honest, I don't think C# is really a serious option anymore here. Here is where I just like Rust a lot more, or even C and C++, because those languages are actually designed for this job. And C# is simply not.
As an experimental showcase though, I think this is cool.
Rust with a garbage collector would also by nice for one moment. Just to see that it's possible.
**Make Code Small Again**
I LOVE this!! Amazing video, Nick. Every year new toolings come out and default sizes only get larger and larger. Long gone are the days of KB sized GUI apps with minimum resource usage. Really hope this makes a come back again.
The idea itself I agree with, but like, this is sacrificing essential parts of the runtime and portability just for code size reduction
Great to see what's possible! Please make a video about bflat, it looks intriguing.
This just so cool. I love optimizations in general but this is something extra. What happened to performance and memory usage along the way?
For this particular project, you say? If it is, I believe that it is very optimized, as the maze game makes full usage of OS API calls and unsafe, self-managed resources. There doesn't seem to be any need for garbage collection at all, in this case.
memory? GC left from building a long time ago in the video lmao (jk jk)
Some ideas for practical usage of bflat would be welcome. Thank you for the video!
Reminds me of the old borland turboc from the 80's which as very fast and could be optimized extremely well. Everything old is new again.
Please a bflat video would make a ton of sense
I don't see myself using bflat in my day job, but I would watch a video about its features.
Yeah, I'd like to know more about the limitations for Bflat... as I have a few apps which call external windows functions, registry, eventlogs, wmi etc... and I have them AOT'd already... but if there's a significant difference in size, that could be interesting
If I'm being honest. My brain is saying two things. The first is "this is really cool" and the second one is "but why?" There are times where just because you can doesn't mean you should. Maybe the Bflat project falls into that or maybe it doesn't. I honestly don't know. It definitely is really neat though.
Look up 4k demos. One I remember is droplets of water, rendered with software raytracing, merging and splitting in real-time (and the program was under 4KB.
This C# demo is in some ways more impressive because it is written in a high-level (sort of, looking at the code) language rather than assembly language, and it doesn't use any crazy tricks like fractal data generation.
Another was the first level of the Interplay game Descent, including music, the 3D level, and lava animations, in 4k.
Another was a terrain generator called "mars", which was, IIRC, about 2.8K, and generated unlimited random Martian terrain (the detail wasn't great, mostly red hills). Still a better plot than most Bethesda games.
Impressive, but in the end i think it more illustrates how the "usual thing" is pretty wasteful and "loose" than anything else. Reason that "trim obvious fat" isn't default is probably because lord knows how much dependency you have on reflection and/or dynamic code creation.
There is also a tradeoff between binary size, memory allocation, startup time and performance. If you optimize towards one of them, you probably loose the others
In this case, he compresses the binary, so startup is longer and possibly you might store both versions in ram, at least for some time. The static loading of libraries prohibits you from usibg gac or sharing the same lib between apps. Size optimisation will not expand loops, so you loose performance on branch prediction
Everything has its cost
bflat sounds amazing! please do a video about it
After seeing this I need to hire Nick to trim one of the applications running on the paying terminal device
Reminds me of that 64Kb game from a couple years back that was a fully fledged shooter with for the time decent graphics and sound, all in a 64 kilobyte install.
Technologically completely different (they used DirectX or openGL to do most of the heavy lifting) but still crazy what can be done with extremely little
farbrausch!
kkrieger?
I remember playing it when it came out and that was more like 20 years ago actually
@@reikooters don't think it was quite 20 years, but more than 10 definitely
@@tellur808 2004!
Thank you for the video Nick, can you make a video where this is related to dotnet api.
Thanks again
I think if this was boiled down to a single tool and simplified command flags it would be super useful if size was something you were focused on.
While I can definitely agree with more than a few posters that this is insane, I'm also going to argue that this isn't really C# - certainly not by itself IMO. But I can at least agree that everything is being orchestrated in C# but it's just P/Invoking into the native land where all the magic happens. So in that respect C# is almost like a Kubernetes to all of the linked (P/Invoked) Services.
It is C#. Every programming language has interoperable capabilities as well as ability to call into the native layer.
Thanks for the video :) Please make a video about bflat too
I wish I could create a framework / engine that takes advantage of this and become a Unity competitor. I wouldn't even know where to start and I've been engineering for 14 years in a completely different field of study. I better get on it...
I appreciate that you didn't want us to have a stroke from seeing egregious code XD
(btw, I didn't see the code yet, still watching the video)
The only thing I am dissapointed by with this video is, not seeing a QR code of the binary exe file :P
I hope that is indeed possible.
Hello Nick,
Please can you make a video on how to start with DSA in C# or a road map kind of video.
Thanks
I would just go with C++ at that point 😅
Nah, Rust all the way.
@@MaximilienNoalrust is just an uglier way of doing the same thing as cpp.
Definitely, I would like to know more about bflat 😂
B flat for C sharp... I see no pun here.
It takes something sharp and commands it to be flat (the opposite of sharp). I guess it could be called RemovEdge or NoEdge, but that's not allowed at Microsoft.
I want to make an IDE based on BFlat where it will have a fully functional nuget package manager and project templates. BFlat 8.0.2 is awsome.
I'm surprised trimming isn't a bigger priority. Bflat looks really cool.
That's like C++ with extra steps at this point 😀
I wonder how allocations work in zerolib if there is no GC, most likely why most things are static. Is there an allocator included in the lib?
No in Zerolib there is no GC
This is amazing!
cool, please do more vdo for bFlat.
also the c# self-contain aot .exe with windows gui from both .net and bFlat.
thanks
Nick never programmed a dam thing on a Speccy ;)
Very good raycast!!!!
If this supports WebAssembly, it would be insane.
Great!
But what does antivirus thinks about this app?
What is that fancy terminal ?
I was actually waiting for the QR code 😢
Any reason you are not switching to the new UI?
Just curios.
Fork bomb in qr? Who test?
I will never ever scan a qr code again 😂
Crazy.
Cool stuff but i would rather see what can be done on api's than a game. Same with the new trimmed containers.
We call it: Evolution, Mr. Anderson...
One day we'll share modern applications on floppy disks
Yes please gives us a video on bflat
DllImport with asterisk as a DLL path is new to me. What even is that?
damn this is insane
And we are still getting the 200GB update to Call of Duty... 🤦♂
This is insane
I dont understand why it isnt done by default (i.e. stripping of unused methods) when it literally saves 90% + of size.
A very cool way to develop malware ... 😅
Bflat? Yes please, give me another.
Such a missed opportunity for bflat to be called Bb.
These settings should be default
I’d love to see the memory usage as well.
Size matters, bigger is better.
Why
Bring us more bflat content 🥹
There's a video from MattKC where he actually put a game into a QR-Code and he also used crinkler. However he could only fit snake into the code. Having a 3d graphics game this small kinda blew me from my chair, not gonna lie.
The zero std lib sais it does not have a garbage collector? So does that mean your game will just memory leak if it ever allocates anything, at any point. I mean I get it for small CLI tools, garbage collection tends to be useless work, because you can just explode the process afterwards. If your total program runtime is a fraction of a second who cares. Is that the intention? Because, I have no idea how I would even deallocate anything in c# by hand. There might be some unsafe black magic.
Very interesting. Some times you need smaller executables, so these are some very good tricks to know about.
I started programming way back when hand coding byte sized registers with switches. I have NEVER understood the size bloat that has been with us in the decades since. All we are doing here is returning to what should have been before memory and disk space became so cheap and we did not have to bother doing it right first time. My own view is that a code executable should always be derived from a complete source code that then goes with compiler/linker tooling options right to the metal of the CPU. None of this proprietary library crap.
I wish they'd named it 'dflat`
Yeah, they went for "be flat" (remove sharpness) instead of musical notation correctness.
Nice, good to know; that didn't come to my mind
If CsWinRT were trimmable, could it perhaps could have been used instead of manual Win32 pinvoking?
I think that we wasting a lot of SSD space to store a lot of dotnet runtime copies
Have you tried running the exe through UPX? Usually that's able to squeeze out 50ish%.
Interesting how you can make it so small but practically not too useful for me to go all the way down. I think the first suggestion to build "self-contained" is a good option.
bflat as name is genius
Michael already did that. C# and #dotnet are amazing.
I read through Michal's entire blog a few weeks ago when this popped up on Reddit. I'm fairly certain he lives on an island somewhere with a white cat and a giant fish tank full of sharks (possibly with lasers attached to their heads).
Man, this stuff is crazy! You are great🎉
This is Michal creator of bflat which rocks
podcasts.google.com/feed/aHR0cHM6Ly90aGVkb3RuZXRjb3JlcG9kY2FzdC5saWJzeW4uY29tL3Jzcw/episode/NmI2OWU4NWYtMzcwMS00ZTRmLWI2NGMtZjZmMTI3MjJlZDVk?ep=14
All game studios should learn this trick, maybe the games will be again available to share via diskettes instead of the size 160GB :D
In modern AAA games most if it's size are 4k videos and 4k textures.
Some repackers let you to not download unnecessary things.
(I'm still buying games tho, but when I was a student - that was a totally different story... ;-) )
@@igorthelight I know :)
Anyone else who thought about a musical scale after watching this... C sharp, b flat, f sharp, where's the rest of the scale. Joking aside, great video Nick!
i’ve been looking at the possibility of using nanoframework for RP2040… there’s been work to add support but it’s rough going. if we could bring Sdk style project and use a similar stack to this video i think it could solve a lot of issues
This is really cool, and shows the potential future of native aot
Nice to see some proper code in C#
3..2..1.. new viruses will come 😅
I'm curious how this improves performance
Fun, but of limited application TBH.
Could be nice if this works with Blazor
awesome 😮
Unity successor may use this.
Finally!🎉
Show me bflat if there's a chance I'll actually use it
Excellent, I knew I shouldn't have thrown my floppy disk drive away..
anything on memory usage and performance of bflat?
Do a video about b flat
This is wild, would definitely like to see more on bflat.
Best in wasm projects. Thanks !
The thumbnail is literally what she said
that's crazy