![Context Free](/img/default-banner.jpg)
- 101
- 1 518 305
Context Free
United States
Registrace 26. 10. 2019
Context Free is about programming languages, including design, usage, implementation, and history.
As for me, my name is Tom. I started programming in Basic as a kid in the 80s. I find both computer and human languages super fun. In addition to using programming languages, I also dabble in programming language design and development. I hope this channel is useful to folks out there!
contextfree.info/
hachyderm.io/@contextfree
contextfreeinfo
github.com/contextfreecode
reddit.com/r/contextfree/
discord.gg/4yJM5MbcAp
youtube.com/@thisorthere
tjpalmer.github.io/languish/
As for me, my name is Tom. I started programming in Basic as a kid in the 80s. I find both computer and human languages super fun. In addition to using programming languages, I also dabble in programming language design and development. I hope this channel is useful to folks out there!
contextfree.info/
hachyderm.io/@contextfree
contextfreeinfo
github.com/contextfreecode
reddit.com/r/contextfree/
discord.gg/4yJM5MbcAp
youtube.com/@thisorthere
tjpalmer.github.io/languish/
Making a language: Structs as Named Args (and also some recursion)
Code: github.com/contextfreeinfo/rio/
- I still haven't fully implemented nested structs yet, either.
- I might still change the term from struct to record.
- I'll probably change multi-value Text ranges to memory-based struct-like storage.
- I plan a fixed size struct-like thing also in the future that can't reference "heap" allocated RC things.
0:00 Intro
0:17 Recursion
1:53 Structs / records
3:14 Structs as named args
4:03 Deep punning
4:33 Keywords vs punctuation
6:36 Parse tree vs normed AST
7:33 Analyzed tree
8:34 Wasm (WebAssembly)
10:30 Outro
- I still haven't fully implemented nested structs yet, either.
- I might still change the term from struct to record.
- I'll probably change multi-value Text ranges to memory-based struct-like storage.
- I plan a fixed size struct-like thing also in the future that can't reference "heap" allocated RC things.
0:00 Intro
0:17 Recursion
1:53 Structs / records
3:14 Structs as named args
4:03 Deep punning
4:33 Keywords vs punctuation
6:36 Parse tree vs normed AST
7:33 Analyzed tree
8:34 Wasm (WebAssembly)
10:30 Outro
zhlédnutí: 3 184
Video
Structs and GC vs RC ripple effects
zhlédnutí 10KPřed měsícem
Code: github.com/contextfreecode/structmem Further analysis by Matheus C. França: gist.github.com/kassane/aee0f7e6dd6b9d1d56b0fe7057ba99d4
6 Programming Languages in 1 Godot Game! Trying out GDExtension!
zhlédnutí 26KPřed 2 měsíci
Code: github.com/contextfreecode/gdext 0:00 Intro 0:46 GDScript 1:41 C# (csharp) 4:15 C (cpp) 8:18 Rust 11:23 Swift 14:19 Zig 18:39 Outro
Making a language: Pretty if/else branching
zhlédnutí 4,2KPřed 3 měsíci
Code: github.com/contextfreeinfo/rio/ 0:00 Intro 0:30 Building, running, & modifying code 1:45 Digging into branch 3:56 Comparing trees 5:31 Inferring types 7:11 Generating Wasm 8:50 Planning ahead
Godot's GDScript for Programmers: Static Types & Memory Safety
zhlédnutí 3,2KPřed 3 měsíci
Code: github.com/contextfreecode/gdpy 0:00 Intro 0:29 Why GDScript 0:52 Exploring in VSCode 1:26 Script as a class 1:53 Python equivalent 2:21 Type checking in Mypy & GDScript 3:33 Declarations in Python vs GDScript 4:28 GDScript Variant type vs nullable objects 5:04 Script class cache 5:38 Reference counting and cycles 6:52 Python cycle collection 8:08 GScript manual memory management 9:50 Pyt...
Past the "Top 10"! - 2023 in Programming Languages
zhlédnutí 4,8KPřed 4 měsíci
Stats: tjpalmer.github.io/languish/ "Top 10" in 2023: czcams.com/video/Tu4bGoOJmPM/video.html 0:00 - Intro / Next 10 or so 0:25 - Next stats 2 0:48 - Functional languages 1:07 - Numerical languages 1:32 - Next stats 3 1:59 - Fun stats down the list 2:26 - Kotlin 2:37 - Swift 2:42 - Dart 2:52 - Ruby 3:00 - Scala 3:07 - GDScript 3:25 - Haskell 3:32 - Elixir 3:54 - OCaml 4:11 - F# (fsharp) 4:22 - ...
2023 News for the Top 10(-ish) Programming Languages
zhlédnutí 4,5KPřed 5 měsíci
Languish: tjpalmer.github.io/languish/ 0:00 Metrics under consideration 0:39 Top 10 programming languages for these metrics 1:01 Python 1:32 JS / ECMAScript 1:52 TypeScript 2:18 Java 2:57 C# / .NET 3:42 C (cpp) 4:41 Go 5:06 C 5:39 Rust 6:20 PHP 6:47 GDScript spoiler alert
Running WebAssembly from my hobby compiler!
zhlédnutí 3,7KPřed 6 měsíci
Code: github.com/contextfreeinfo/rio 0:00 Intro 0:53 Internal & Wasm representation 1:58 Support scripts & export example 3:15 Wasm generation 3:43 Stages & type representation 5:30 Compiler internals 6:08 Type inference strategy 8:38 Core module 9:02 Main function and friends 10:12 Keep on trucking 11:35 Running junk 12:25 Prep for tooling 12:56 Summary
Fast, Friendly, Functional: Roc language creator Richard Feldman, with co-hosts CodeNextDoor
zhlédnutí 6KPřed 7 měsíci
Part 2: czcams.com/video/_fvS0_B6BD0/video.html Demo code: github.com/contextfreecode/rocdemo Roc site: roc-lang.org/ 0:00 Video intro 0:13 Demo 3:42 Interview setup 4:00 Intro 4:47 Governance 5:38 Relationship between Roc and Elm 6:48 Elm outside JavaScript 7:41 Differences between Roc and Elm 10:08 Roc lists and opportunistic mutation (functional-but-in-place) 13:04 Roc abilities, similar to ...
4x shorter WebGPU access from Wasm, featuring Nelua, Zig, & Rust
zhlédnutí 6KPřed 9 měsíci
Code: github.com/contextfreeinfo/taca Previous video on Taca: czcams.com/video/VhCgep06-I8/video.html WASM-4: wasm4.org/ Ambient: ambient.run/ (which also intends to support running in browsers) 0:00 Intro 0:48 Short header for GPU access 2:13 Quick review of simplified demo in Zig 3:34 Size comparison 3:57 Reviewing options 5:06 Rectangle for shaders 5:36 Nelua code 6:37 Build and run script f...
Starting my own hobby language (again)
zhlédnutí 7KPřed 10 měsíci
Code: github.com/contextfreeinfo/rio 0:00 Intro 0:58 Project config 1:19 Processing flow 2:19 Lexer 3:01 Parser 4:08 Tree structure 5:40 Normed/abstract tree (AST-ish) 7:34 Parse tree vs normed tree diff 8:19 Resolver (working toward runner) 10:52 Core library thoughts 11:27 Demo run 11:50 Def lookup 12:39 Outro demo
Browserless app runtime in Rust - Demo app in Zig - Wasm/WebGPU
zhlédnutí 31KPřed rokem
Code: github.com/contextfreeinfo/taca 0:00 - Intro 0:24 - WebGPU and webgpu.h 2:10 - App demo 2:40 - Header files 3:40 - Using Tac/Taca & WebGPU from Zig 5:04 - Shaders 6:15 - More app tour: size, code, & data 6:45 - Build scripts 7:38 - Rust runtime, Wasmer, WASI, security 8:53 - WebGPU interfacing and fake pointers 11:06 - State of capabilities, outro
Coding raw WebAssembly Text - Dive into Wat
zhlédnutí 6KPřed rokem
Code: github.com/tjpalmer/rio/tree/again/explore/wasm 0:00 - Intro & Demos from Ben 1:06 - Hello in Wat 1:49 - Mini Wasm runner 2:36 - Fibonacci numbers in Zig 3:30 - Fibonacci numbers in Wat & Wasi 3:49 - Wasi 4:33 - Main loop, signedness 4:57 - Manual stack 5:28 - Calculating Fibonacci using Wasm stack 6:05 - Program run, more operand stack, binary size 7:04 - Print text and numbers using man...
Programming Languages Festival! - Update: Funding failed. Event now canceled.
zhlédnutí 3,8KPřed rokem
Update: The kickstarter failed, sadly, and the event is now canceled. I looked through some plan B options, but things didn't seem to be working out for the original schedule. Maybe some variation will work someday but nothing's announced at this time. For historical record for now, the announcement site is still at plfestival.com/
Using COBOL to make a video game!
zhlédnutí 28KPřed rokem
Code: github.com/contextfreecode/cobol-explore Kenney: kenney.nl 0:00 Intro 0:42 Simple example 3:39 Generated C code 5:01 Source columns 5:47 Variables and memory 6:32 Game code and paragraphs 7:22 Copybooks 8:54 Helper C file for SDL access 9:38 My own generated data files 10:00 Build commands 10:43 Game demo 11:10 Utility subprograms 12:10 Text formatting 13:09 Syntax and core language featu...
Gleam, a typed language for the Erlang VM - Interview with creator Louis Pilfold
zhlédnutí 9KPřed rokem
Gleam, a typed language for the Erlang VM - Interview with creator Louis Pilfold
Compile WebAssembly on Linux to native Windows using Wasmer & Zig
zhlédnutí 6KPřed rokem
Compile WebAssembly on Linux to native Windows using Wasmer & Zig
Int overflow (or not) in C++, Ruby, Zig, Rust, & Pony
zhlédnutí 28KPřed rokem
Int overflow (or not) in C , Ruby, Zig, Rust, & Pony
Reference Cycles in Rust, C++, and C# (safety part 2)
zhlédnutí 9KPřed rokem
Reference Cycles in Rust, C , and C# (safety part 2)
Memory safety in C++, Zig, & Rust (part 1)
zhlédnutí 54KPřed rokem
Memory safety in C , Zig, & Rust (part 1)
From Turbo Pascal to Delphi to C# to TypeScript, an interview with PL legend Anders Hejlsberg
zhlédnutí 45KPřed rokem
From Turbo Pascal to Delphi to C# to TypeScript, an interview with PL legend Anders Hejlsberg
Carbon got your eye? Using C++ libraries today from Jakt & Nim
zhlédnutí 15KPřed rokem
Carbon got your eye? Using C libraries today from Jakt & Nim
Context & dynamic scope in Lisp, Jai, Odin, TypeScript, Haskell, and more
zhlédnutí 8KPřed rokem
Context & dynamic scope in Lisp, Jai, Odin, TypeScript, Haskell, and more
Jai vs Odin systems programming languages (Non-spicy takes!)
zhlédnutí 70KPřed rokem
Jai vs Odin systems programming languages (Non-spicy takes!)
Grain, a WebAssembly functional language - Interview with co-author Oscar Spencer
zhlédnutí 11KPřed 2 lety
Grain, a WebAssembly functional language - Interview with co-author Oscar Spencer
Optionals and errors in Haskell & Rust - Monads by example
zhlédnutí 15KPřed 2 lety
Optionals and errors in Haskell & Rust - Monads by example
April First joke - Programming language designers unite!
zhlédnutí 11KPřed 2 lety
April First joke - Programming language designers unite!
Avoid throwing exceptions? Error, null, & bool handling in 5 programming languages!
zhlédnutí 16KPřed 2 lety
Avoid throwing exceptions? Error, null, & bool handling in 5 programming languages!
Awesome tiny games in 11 programming languages - WASM-4 Jam 2022 results!
zhlédnutí 11KPřed 2 lety
Awesome tiny games in 11 programming languages - WASM-4 Jam 2022 results!
V-lang have them both beaten for my kind of programming. The error handling has an explicit out-of-band handling that you cannot screw up.
Delphi was your best work, Anders! Unfortunately, Microsoft destroyed it...😉
nice format
Liked the video, but the diffs added too much noise to clearly understand what the difference were. I guess it would've been better to highlight the diff while going through post-production.
This is a very interesting conversation. Sorry I am late to the party.
"if err != nil" > *
Yeah, Zig was much better than Rust here. And damn, Rust is very unreadable. It manages to be as bad as reading code in C++.
It’s fun seeing this project progress. Also, it would be funny if you optimized tail calls by emitting a “return_call” instruction
I missed that that's standardized in wasm already. I'll have to see the support for that. And I'd want to have explicit tail call indicator of some sort in Rio for that, I think. And I'd eventually want to verify it in the Rio compiler if so. But yeah, I think tail calls are great when verifiable.
And thanks for drawing my attention to it! And I'm not yet sure exactly how I'd want to indicate it in Rio syntax yet.
I'm watching and thinking rn: thanks god and SPJ we have proper constrained overloading in haskell, and not _this_
I love seeing the progress on Rio! I'm assuming it has structural typing, judging by the fact you can create anonymous records using the struct function?
Thanks for the encouragement! I'm actually leaning toward nominal typing, and it's actually nominal right now. I should have mentioned that in the video. The = is a fixed definition, then I track it as a distinct thing. I love structural, but nominal is easier to code in the compiler and easier to report in messages (although I don't have messages yet). Maybe easy spread syntax will get some of the advantages of structural also. But I also need to see how it goes. Some people want design set in stone in advance, but I'm still winging it some.
I do also plan separate "packed" (somewhat like Rust "Copy" trait) and "class" types from "struct", where packed and struct act like C# record types also in ways, but classes are opaque abstractions. And might still say "record" instead of "struct". Thinking about that.
You've already done more to show how to work with Wasm than every other tutorial I've ever seen, because you showed how strings work. Every other tutorial stops at integers, which is kinda useless. So, thank you! One of these days I want to try building a Wasm language, but I really don't have the time for figuring out all the little details like that.
Glad the videos are helpful to you! And yeah, life balance is tricky. Gotta make the decisions that are right for your situation, whatever those are.
And I still need to study wit (wasm interface types) sometime.
@@contextfree I'd love a video on those and how to use them! Really, any walk through of how you've done what you've done would be helpful.
have you looked into algebraic effects? ive been researching them and just wanted to know what you think of the idea
I've played with Koka some, but I still don't feel super familiar with them. For Rio, I plan to indicate in effects in some fashion, maybe even just by required args, but I probably won't go full algebraic effect handling or anything.
Just looked it up and read a blog post on it. Is it not just dependency injection? I get that it goes up the stack to find the closest 'handler' for a certain effect, but similarly you can pass dependencies down.
By "required args", I effectively meant dependency injection. Some languages make effect handling a primary language feature though, and maybe combined with coroutines and such, they get more low-level flow control out of it. But I can't speak authoritatively on the subject at all.
I have some videos on effects and also dynamic scope where I explore the subjects in a limited way, but that's as far as I've gone.
Why is call it rio?
I've been calling my hobby language plans Rio for decades, even though the specific language plans have changed over time. It's had more meaning for some of those language variations than others (in the "river" sense of the word). But it's primarily named for my fond (and sometimes not so fond) memories of Río Blanco, San Marcos, Guatemala.
Rio conveniently also might remind people of Lua, which is nice because I aim to be small in implementation and feels like Lua is. If the R reminds people of Ruby, that's also not so bad. Even though Rio is statically typed unlike default Lua or Ruby.
And might remind people of Lua since that comes from a more famous place with Rio in its name.
And sorry for the spam, but maybe only 10-15 years of using that name for projects and ideas.
@@contextfree and Rio languages it will only be a hobby or plans that are something real?
Man I love this channel so much. You have actually inspired me into taking college courses in the formal logic of programming languages (such as lambda calculus) and I have been absolutely loving it. Thank you!
The structure arg running kinda reminds me of "the other side" of struct decomposition patterns in a function definition, like in JS or F#. Cool idea
And I hope to have destructuring definitions and pattern in matching in Rio also. If I allow those in arg position for ad hoc arg struct types, it would look just like defining named args also, but I'm not yet sure if I want ad hoc structs like that. And I'm moving slow here, clearly, so we'll see what gets done. Thanks for the comment!
I love where this is going!
Any reason for using wasmi_cli instead of wasmtime?
I've often used wasmer for cli execution in past videos, but I like to check on at least some variety of wasm engines, and wasmi is a lightweight and performant interpreter that's well maintained. I haven't done it yet, but I'm inclined to automate running of all my test/example programs using wasmi. I regularly manually check on wasmer as well. And wasmer is surprisingly fast startup for being a compile-to-native engine. And yeah, I probably should be checking wasmtime also.
Is it possible to use WebGPU without webpack and node.js stuff? Just pure WebGPU and browser?
Yes, that works, although I didn't do any browser nor js stuff here.
Odin is very readable language, i can easily read odin code and understand what it does, because the syntax have much less noise.
Not structs, but records
Mind explaining more?
@@contextfree We don't put structs into database tables. We put records into database tables. They are records
So you would prefer if these languages had used the term "record" instead of "struct", if I understand correctly. Interestingly, C# has a language feature called "record" these days, and it means something different than "struct" there. More to what seems to be your main point, long ago I learned C before learning Pascal, so I learned the term "struct" first. Although I think you're right that "record" has a longer history in such usage.
@@contextfree Yes. Ada, Modula, Oberon, Oxygene, Icon, they all have records. But whatever Haskell you take from outside the family, it also has records
This is not a perfect comparison. In your C++ example, there's no need for the Seq struct to be copied when it can be passed as a reference. The refcount increment op of shared_ptr is expensive because it is atomic, therefore passing it to every function that operates on the underlying object will slow things down considerably. Generally, the use of shared_ptr is relatively rare, but if you do use it, it shouldn't be passed by value to any entity that does not require ownership of the memory.
Thanks for the comment! Yeah, I purposely passed by reference to the main printing function in both C++ and Rust to have examples of pass by reference here in addition to the examples of passing by copy/clone.
I just didn't mention it in verbal discussion, and maybe I should have.
Apparently there's a web assembly gd extension now. So every wasm language is now fair game too 😂
Fun fact: writing is cheaper than reading. Also modifying has nearly same cost as writing; higher if anything because you need to read a cache line first to modify it. However, the problem comes if the new value should be seen by 2+ objects simultaneously.
why are you invoking the toolchain as part of a benchmark, just run the outputted binary
When I remember, I always measure cli time in my videos. My videos are edited, but I try not to edit command execution, and keeping the time there is part of that. I'm also interested in compiler speed. I'm not benchmarking here. But a viewer did do some benchmarking, even if this still is just a micro benchmark. I've linked to that in the video description.
I prefer Rust, the Rust language is not only a memory-safe language, but it simplifies the complexity of C++ syntax that is overextended due to modern language features, but what about C#? It's a copycat of Microsoft's special version of Java, it runs in a VM, and garbage collection cannot be removed...
I abandoned learning Rust because there are so few jobs in it, and getting a job as a programmer at a quality company when you're in your mid-late 50s is hard enough as it is. I didn't get to the point in my Rust journey where it ever felt like I wasn't fighting the language, but I truly believe that I would have, eventually. The main thing that I love about Rust is the way enums are first-class data objects, and the way the compiler makes sure you're covering every possible value that can be returned (if the return type is an enum). It feels so natural, and I wound up writing functions that looked a lot like finite state machines, which I find particularly easy to understand and reason about correctly. It is my understanding that this feature is common in functional languages; even if that's the case (pun not intended but duly noted), Rust is the first time I remember encountering it in a C-derived language. (Actually, now that I think about it, I also really miss that attribute system, which took a while to wrap my head around, but has profoundly changed how I think about many problems, to the point that I've become really interested in tagging systems in contexts other than programming. I know Rust isn't the first language, or even C-derived language, to use something like attributes, but it's the first time I encountered it as a core language feature.)
@@andrewgr144 You are right, Rust is not a good choice for work reasons, but I only learned it because of its modern features. I worked for a company that made set-top boxes, and the original code of the company's product had a lot of unused annotations. And a large number of global static variables, and the inexplicable insistence on using the ANSIC standard makes the original code messy and difficult to maintain. I don’t understand why the company insists on using the C language. Obviously the tool chain provided by the set-top box supplier provides g++ related files. There is nothing missing. Using C++'s data encapsulation function and construction and destruction function can enhance the readability of the code and simplify a lot of complexity. Of course, this is a story later. The company's programmers do not have the ability to C++. they can't even understand the construction and deconstruction functions provided by the C++ language. This is a company where engineers insist on only doing their own part to clean up the trouble. After many years, I learned that the internal state of this kind of company is very important to a China mainland company. The company is the norm. Fortunately, I left my job early. At that time, I still had the enthusiasm for new technologies and the insistence that the code should be beautifully designed. I was not suitable to stay in such an aging and decadent company.
Turning off optimizations makes zero sense. It also seems odd to say the c++ was less efficient when your own timing shows it's 3x faster.
The timing includes compile time, because I care about that also. One viewer did some actual timing analysis with fuller optimizations, though, using Rust, C++, and D (in multiple configurations). See the link above in the description.
Worth noting that even the benchmarking linked in the description is still limited to this simple program, which is a micro benchmark. Hopefully the measurements manage to exclude IO time as well, but I didn't ask that.
It looks like VScode wants to update.
interesting topic. now since we talk about C# and C++ performance, would you please take a look at both Unity Engine and Unreal Engine ? both which have introduced new technologies to address some challenges with their primary programming languages. Unity, which primarily uses C#, has introduced Unity DOTS (Data-Oriented Technology Stack). DOTS emphasizes on an data-oriented approach to game development, focusing on maximizing performance. also their new Burst Compiler which is part of this new stack. (The Burst Compiler is a high-performance compiler specifically designed to optimize C# code for performance on modern CPUs. By analyzing and transforming C# code into highly optimized machine code) On the other hand, Unreal Engine, which primarily uses C++, has introduced a new programming language called VERSE. which is designed to address some of the complexities and limitations of C++, particularly in terms of memory management and performance optimization.
So, what language should I use to hack the Pentagon?
Makes little sense to me… All examples are single-threaded.
What adjustments would you like to make for a multithreaded look at the topic?
@@contextfree What happens when you mutate your struct from different threads? In Cpp it works (except it rarely causes data races?), in Rust it doesn't (Rc is not Send, have to use Arc<Mutex<FearlessConcurrency>> instead), in C# I don't know… Also, C# tracing GC stops all (most) threads when it runs but the other two guys don't?
I really like the copy/clone distinction in Rust. Is there any particular language that this idea came from or is it new?
One place I've seen `clone` before Rust is Java, where they say that "by convention" the cloned object "should be independent" of the original object, meaning deep copy of anything mutable, and I suspect the Java method name may have influenced Rust's naming, but I don't know what predates Java in that, nor have I dug up conversations from Rust development. And of course, Java still has no value/copy types outside of primitives quite yet, although possibly coming soonish.
Very nice video!
I used to say for a while GC languages solved some memory and reference issues decades ago that rust and c++ try to find sophisticated solutions for. However the concept of GC is elegant compared to what you do in these other languages. It just doesn't have optimal control and runtime performance. I think though that if people were serious about performant GC code then they would find ways to make it 90% the speed with some exceptions.
Trade-offs exist for most things.
Semi-serious question: would it be possible to provide hardware acceleration for GC? ("Semi-serious" because I don't know exactly how GC works, and if it would make sense at all to do this. But I'm guessing that if it hasn't been done yet, especially given how common GC languages are, then it's probably a silly idea. Or maybe it's not a silly idea, and we can get by fine by just throwing more powerful generic hardware at the problem... 🤔)
@@vlc-cosplayer No immediate answer from me. I'd have to study that for a while.
@@vlc-cosplayer good question, I think the overhead wouldn't be worth it, because the best solution is to keep as much memory as possible for as long as you don't need it for something else. Really memory management is only necessary for Operating Systems with concurrent applications that need your memory. If you manage memory for your own application you can just keep the memory address to a large piece of memory and return the last the end of the piece of memory and assign on top of that. That is how arenas do it. So all this memory management issue is largely a multiprocess issue.
Speed isn't necessarily the issue with GC languages, and in fact I think it might not even be the issue the majority of the time. The other issues are predictability and constancy of execution time. For example, say you're writing the back end for a massively multiplayer game of some sort. It could be the case that the mean, median, and modal performance averages are all plenty fast enough, yet your decision to use GC dooms your game to poor reviews and player retention, because some small percentage of the time, the GC runs and sees that something can be deleted, but by deleting that thing, it now sees that some other stuff can be deleted, etc., in a cascading effect that leads to a noticeable lag in the game. The conditions for creating this lag may be incredibly rare as a percentage of the number of times the GC runs, but the GC may run often enough that the lag is still occurring every five or ten minutes of real time. (I think maybe a high-volume day-trading stock system might have made a more compelling illustration, but my mind immediately goes to games, and I'm sure anyone who reads this comment can see how performance lags due to GC would be disastrous in that scenario-- if the GC is fast enough for 999/1000 trades to get executed flawlessly, but 1/1000 times there's a half-second delay, allowing the many competing auto-trading bots to make their trades first, those delayed trades might completely wipe out the profit margin made by the other 999.)
Why dotnet 7? Should try this with dotnet 8 AOT.
It's what's currently handy on Compiler Explorer. They also have an unclear "main" option. I suspect 8.0 is coming there sometime.
@@contextfree aaa nice to know
dotnet 7 also supports AOT
@@Liphi yes but codegen for 8 is much better as libraries get more annotated for AOT
@@metaltyphoon I mean, that's just a basic struct manipulation. Doubt that .net 8 can change something here
Interesting video but I am missing the point of the video. Your comparison of C#'s CLR instructions with C++'s x86 assembly is just unfair. It seems you dislike the extra syntax that rust adds on you when you want to copy an object. It would have also been interesting to compare a 'real' application (in the 3 languages) with full optimization instead of a minimal program that you manually need to prevent inlining.
Yeah, I rarely express opinions directly in my videos (although I actually like Rust clone vs C++ implicit copy constructors, but don't tell anyone). I usually just explore stuff. And RC optimizations are definitely an interesting topic that I avoided discussing here.
One of many interesting video topics could be exploring heavily compiler-optimized C++ and/or Rust and/or Swift RC in simple cases vs say Perceus RC such as in Roc or Koka. Haven't explored that yet, though.
@@contextfree After a few years of C++ i love to remove implicitly as this leads to the worst errors. At some point I created a hardware interface implicitly from string which caused havoc :)
@@contextfree It could be as simple as reading numbers from file, adding them up and printing the sum to terminal. With godbolt its great that you can compare different optimization levels and see when the compiler starts using SSE instructions.
C# app was also in x86 assembly (aot or after jit). IL looks different
luv me float * ‘ate reference counting and GC simple as
Nice to see the Godot ;)
Nice and to the point comparison. Usually though you are not supposed to pass shared_ptr unless you actually want to share ownership. In adequate cpp codebases about 95% of ptrs are unique (or bound to an arena) and parameters passed by ptr or ref most of the time. Plus shared_ptr's ref counter is atomic, which adds overhead. While ago I had to optimize iphone 4 game where like 20% of frametime was spent copying pointers arround 'cause people who developed it were used to garbage collected languages. If used naively RC can absolutely affect performance negatively.
Yes, in some cases if we have predefined lifetime, `ptr*` will be best solution (probably in some wrapper).
So I take that your argument is that multi-owner semantics is easier to describe in C# than C++ (and perhaps Rust). This is of course true, given that there is no concept of ownership in GC languages. But I would argue that multi-owner is something that should be avoided if possible, as there are many pitfalls; and in particular shallow copies are more surprising and difficult to understand than deep copies (e.g. why is the int is different but the list isn't?). I don't buy though the performance argument though: shared ptr needs to do a lot more stuff so that 1. it is thread-safe to some extent, and 2. it does need to keep track of the weak ptr bookkeeping. The performance hit is translated to the GC with its own set of tradeoffs (you probably implied this), so there's no free lunch. That's not to dismiss the amazing work of the C# compiler devs, of course.
Data is ownership is a thing in GC languages, including C#, they're just not exposed to the programmer, but the GC algorithm needs to know who owns the data and for how long so that it can `safely` drop objects. This process can be quite fast and efficient, the problem is that reference counting and data dropping is not done eagerly for a lot of reasons, so you end up with these performance dips that can be unpredictable.
@@user-uf4rx5ih3v Oh sure, you're right. I should have specified *user-facing* existence of it. Of course that will matter in implementation details, for performance, etc.
@@japedrEven as a user you still have to think about ownership sometimes. For example when you have to ask yourself, should this be a regular HashMap or a WeakHashMap? And if you guess wrong your objects either spontaneously disappear or start hogging up your memory.
I disagree. Shared ownership and mutability should be used very sparingly. Shared ownership itself is absolutely fine and often a nice tool to keep track of context.
The comparison shouldn't come close though... Shared pointer is literally just an atomic size_t variable that gets incremented and decremented, and deletes the pointer to the held object if the reference hits 0; that's incredible cheap to the point of being almost zero-cost. Garbage collection has MUCH more work to do with walking through the list of items and checking to see if an object is still "reachable" from the programs root. I've personally built my own custom "shared_ptr" type that offers additional functionality from the standard library, and it's much much easier to implement than even a custom container type would be, let alone writing anything resembling competent garbage collection.
**I was wrong here its really is displaying the actual x86 assembly, appologies** In the C# case you are not looking at x86 assembly. Instead its .NET interpreted code. They just happen to look very similar in this case.
Are you sure? I also don't really know CIL, but .NET has AOT compilation sometimes, and those registers and instructions look like x86-64 and don't look like this example of cil here: en.wikipedia.org/wiki/Common_Intermediate_Language#Example
Or rather .NET supports AOT compilation these days, and I suspect that's what they've configured on Compiler Explorer. See also: github.com/compiler-explorer/compiler-explorer/pull/3168
@@contextfree oh nice didnt know that!
it's*
@@contextfreeThose are assembly instructions, but you don't need aot for assembly instructions
Very cool
Very interesting insight! I wouldn't consider that GC can make some things simpler, although now it totally makes sense. Thanks for sharing!
The entire point of gc is to make things simpler
@@stercorarius right, I meant simpler for the compiler/CPU, as in it has to do less work (at given time, because obviously it will have to do the work later)
nice nice nice
I have been preparing a series of posts on my blog about memory and this helps me a lot to understand and complement it, it is great.
would help a lot if you tell us what your blog name or url
Hey, can you share your blog?
I chatted a bit with Jonas and confirmed that this is his blog. It's still brand new, but he has some additional posts planned, such as he mentioned above. jonas1ara.github.io/
I started out as a C developer, but that was a long time ago. Now, if I try to go back or try to work with libraries for C or C++, I feel demoralized. Things seldom seem to be setup out of the box. Sometimes you need Visual Studio, others you need GNU environment of some kind. Either you're struggling with the IDE project configurations, or CMake, which is whole other language in itself. This is my rant on C/C++ development and build tools. I'm tired of hearing about Jai... Its been year now, so its not an option for anyone who wants to do something today. I'm interested in Odin : )
Odin is definitely a great option for people that like C but want something more convenient and more modern.
It does a half ass job full of bugs with c#, why they keeo waste resources with anything else
3 years now, Where is my 1.0 Andrew? (Joking, I love zig and I think it should take it’s time to become the greatest)
Really good video. I hope you keep uploading nice things! Subscribed
Very interesting. I wonder about how well Zig will perform when being used inside GDExtension. Do you believe that the way Zig allocates memory could be a problem?
this makes me remember how super sweet coffeescript is/was. props to nim, too!