31
u/gnus-migrate Jan 01 '24
I really wish he would expand on this, but he never does. Is it the need for custom allocators? Is there a lot of unsafe pointer casts? Do they have a lot of shared data structures? What are those structures and why isn't unsafe rust enough to properly implement them?
I know this was probably a stream and he just wanted to answer the commenter quickly, but it would be really interesting to have an answer to this.
20
u/Tabakalusa Jan 01 '24
Casey goes a bit more into it, when he talks about it.
The pattern he seems to advocate for mostly seems to be fairly straight forward. If you've got any kind of task, allocate the memory you are going to need for that task up front, work within that allocation with a custom allocator and then just clean everything up once the task is completed. This can apply to entire programs as well, especially short running ones. Just allocate memory as you need it and let the operating system mop it up once the process exits.
This can be annoying to do in Rust. Richard Feldman, creator of the Roc programming language, has touched on this a few times as well. He has talked about it in the context of cli tools, which are usually quite ephemeral, as well as in the context of web-servers, which might just do a big arena allocation for every request and clean it up entirely once done.
He recently had Casey as a guest on his podcast - Software Unscripted - where they talked about this as well.
11
u/gnus-migrate Jan 01 '24
I've never really used custom allocator, but as far as I'm aware there are arena crates for Rust. Why aren't those enough?
21
u/matthieum [he/him] Jan 01 '24
An arena allows dumping all your allocations in, but not organizing them.
If you want to organize data -- sort it, build a look-up table, etc... -- you'll need collections -- Vec, HashMap, etc... -- and for those NOT to allocate memory you'll need a custom allocator around your arena.
6
u/gnus-migrate Jan 01 '24
I guess my question is that is it just an ecosystem issue or is the language itself preventing this style of programming? Jon's opinion seems to be the latter but, from what you described it sounds like the former.
Maybe I misunderstood.
39
u/matthieum [he/him] Jan 01 '24
It's mostly a standard library issue:
There's no (stable)
Allocatortrait, orStoretrait as I would prefer it.(Stable) collections cannot be parameterized with a custom allocator (implementing
AllocatororStore).Which ends up being an ecosystem issue, since in the absence of a standard trait, there's no rallying vocabulary type to offer custom collections parameterizable by custom allocators.
Unfortunately, the RFC to drive
Storeforward is basically dead as I'm getting no feedback and the design work onAllocatoris similarly not progressing... not enough people interested, I guess.So it may very well be a community issue at heart, in the end?
There is a slight language issue for
Store:CoerceUnsizeddoesn't work on handle + metadata, because of the lack of typed metadata which implementCoerceUnsized. It's a problem I raised during the design of the metadata API, but it was decided to start with an untyped core (easier) and leave a possibly typed API to later... which is fair enough, but will be required at some point :)11
u/Comrade-Porcupine Jan 01 '24
I am very disappointed to find that Allocator/Store is dead? That's shitty.
I would give feedback but I can't say I'm super qualified other than to say: this is desperately needed in Rust, and is a major weak point. And so it's a real bummer that progress isn't being made.
Unfortunately I feel like the lack of progress on this and on portable simd is indicative of a community/audience problem with Rust, excuse my rant:
Despite being advertised as a language for systems programming, it has overwhelming become a language for people writing web services, instead. And so the important things that would be genuinely useful for OS, database, embedded, games, etc are languishing, while we get N iterations on async web frameworks and the like. Which I don't really get, since there are other languages which are arguably more suitable in that domain.
Unfortunately if this continues down its path I fear many people will simply change channels back to C++. I've been tempted, myself.
11
u/matthieum [he/him] Jan 02 '24
Unfortunately if this continues down its path I fear many people will simply change channels back to C++. I've been tempted, myself.
I find this somewhat amusing, seeing as C++ does not have portable SIMD either, and may suffer even more from a fragmented community -- the "split" of Google after the rejection of ABI breaks proposals and the launch of Carbon coming to mind.
Despite being advertised as a language for systems programming, it has overwhelming become a language for people writing web services, instead.
I wouldn't say so.
Go is clearly designed for writing web services, for example. Goroutines are admittedly a more ergonomic alternative to
async.Rust went with
async-- and a straightforward version of it, unlike C++ coroutines -- specifically because it was a better fit for low-level programming. As a result, we see async runtimes such as Embassy, specifically designed to run on small embedded devices.With that said, I do regret the lack of focus on foundational bricks such as
Allocator/Store. I would expect there's a number of reasons: busy people, few experts, hard to evaluate trade-offs, etc... all leading to slow progress.And I'm not quite sure how to spur efforts and push for progress.
1
u/gnus-migrate Jan 01 '24 edited Jan 01 '24
Thanks a lot for the detailed answer! That's sad though, it's a really interesting use case for Rust.
Edit: removed the last part, I'm not involved in rust so I don't want to put undue pressure on maintainers.
4
u/matthieum [he/him] Jan 01 '24
I agree it's sad :) It's definitely a usecase I'd like to see taking off -- I didn't author the RFC out of disinterest, after all -- but it seems there's too few people interested enough for now.
1
u/Feeling-Departure-4 Jan 01 '24
Does it work on nightly for parameterizing std collections? Maybe I misunderstood.
In addition to adding more arena support, the allocator API sounds like it would be helpful to allow higher alignments onto the collections' internal buffer than the element type itself warrants. This is useful for (mutually) aligned loads for SIMD.
4
u/matthieum [he/him] Jan 01 '24
Does it work on nightly for parameterizing std collections? Maybe I misunderstood.
Some collections (such as
BoxorVec) have been parameterized, but others (such asHashMap) have not yet, due to uncertainties about the API.In addition to adding more arena support, the allocator API sounds like it would be helpful to allow higher alignments onto the collections' internal buffer than the element type itself warrants. This is useful for (mutually) aligned loads for SIMD.
Allocatoris not type-dependent (and neither isStore), they allocate raw memory of the specified alignment and size, so this usecase is supported "out of the box".1
u/Feeling-Departure-4 Jan 01 '24
Hmm, thanks. So you are saying I could implement something to pass to Vec currently?
1
u/matthieum [he/him] Jan 02 '24
On nightly, yes you could.
You "just" have to pass the
Aparameter, which should implement theAllocatorAPI... which is fairly straightforward.0
Jan 01 '24
[deleted]
1
u/matthieum [he/him] Jan 02 '24
It's certainly possible.
There could be quite a maintenance burden as code does change over time, and quite a few stumbling blocks as
stdtends to use features that are still unstable, but it should be possible.4
u/Plasma_000 Jan 01 '24
There's already crates such as bumpalo which offer data structures which get allocated into an arena. However once the allocator API is stable that's when everything should just work without needing to reimplement data structures.
1
u/HildemarTendler Jan 01 '24
While this isn't a memory leak, it can create the same problem. Limiting allocations and destructions is great, but I suspect there is more to it than this or else you'll slowly eat up all available memory.
2
u/Tabakalusa Jan 01 '24 edited Jan 01 '24
What are you referring to?
If your talking about just not freeing memory and letting the OS reclaim it when the process exits, that is only going to work for processes that complete their task in some bounded amount of time/memory.
As for allocators, I'm unfortunately not super knowledgable about working with them. From what I gather, the idea is very much being more conscious about the allocations you are going to be doing up front, and working within those confines. I'd imagine it is also going to depend very heavily on the type of allocator you are working with and how gracefully it deals with running out of memory. Maybe your allocator can just request another arena from the allocator it got allocated by, all the way up the chain back to the global allocator, maybe you just return an error, etc.
The typical method of just allocating memory whenever you need it, is one of the things Casey dislikes about languages like Rust. In the podcast episode, he says something along the lines of "Rust makes arbitrary allocations and deallocations of memory safe, but I consider that approach to memory management an anti-pattern in the first place. Therefore I'm not interested in Rust, because it isn't actually solving a problem I am having" (this is very roughly paraphrased!!).
5
u/VicariousAthlete Jan 01 '24
One of his critiques years ago is how exploratory programming is useful for games, and how that is a pain in Rust due to the strict typing and memory safety enforcement. You want to just quickly try out some idea so maybe you don't care if you do a quick memory leaky implementation or lean on implicit type conversions etc. I even maybe agree with that take in the context of single player games, where memory bugs are at worst just a crash. And single player games are what he has focused on so far.
2
u/oconnor663 blake3 · duct Jan 03 '24
I think the whole story is probably some mix of "yes Rust makes scrappy programming hard" and "the idioms for doing scrappy things in Rust are unfamiliar". Examples of the latter are things like Box::leak and SlotMap.
-7
u/log_2 Jan 01 '24
Probably Rust takes too long to learn well, whereas with JAI anyone can jump in and easily start using it productively. He didn't want to dedicate the 2+ years needed for internalizing Rust's idioms.
11
u/moltonel Jan 01 '24
That's a big exaggeration of how long it takes, especially for an experienced programmer.
32
u/anlumo Jan 01 '24
I never disagree with him on the facts, but his hot takes are always very… subjective. He has some very weird ideas on what makes a good programming language, but it’s really hard to argue against someone with his amazing track record.
51
u/-Y0- Jan 01 '24 edited Jan 01 '24
His takes are wrong too. C++ isn't that faster to compile than Rust and it's widely used in game dev.
And his track record with JAI is not that great.
9
u/anlumo Jan 01 '24
With the track record I'm talking about his games, not the technical output.
One of the biggest advantages of Rust is that programs are much more stable, but Braid and The Witness never crashed on me either (unlike many other AAA games).
Jai seems to be ignored by everyone else though. I haven't looked into it myself.
32
4
u/-Y0- Jan 01 '24
Braid was a cute little platformer, but Witness was imo an interesting game that turned into a massive time waste by the end.
Jai is ignored because there isn't much to pay attention. Plus the licensing behind it is weird and it's only support seems to be Jon.
4
Jan 01 '24
We went from "his subjective opinion is wrong" to "his games are mostly mid" real fast, unless we gonna pretend that opinions are facts only when it's our opinions or we're agreeable with.
6
u/-Y0- Jan 02 '24 edited Jan 02 '24
No, we went from he is objectively wrong - mentioning compile times as a benefit of C++, to he has a track record. And I am putting doubt on that claim. He made Braid, which was brilliant, made Witness, which IMO is not that great, and made a language that's basically proprietary and is heavily restricted.
Nowhere did I say his games are bad, just that his actual track record and the track record perceived by /u/anlumo are not really the same IMO. He was an indie star during the early start of XBLA (along with Fez and Super Meat Boy), but I'm wondering how much of that is being at the right place at the right time.
1
u/anlumo Jan 02 '24
Still, the game design wasn’t part of the discussion at all. We’re not game critics here, we’re developers. Did you ever run into technical issues with his games, crashes or slowdowns?
Compile times I’ll give you. He says himself that he never got beyond a hello world in Rust, so his experience in that area are spotty at best. Due to lack of header files, incremental compilations are typically faster in Rust than in C++. However, if all you ever did was compile a hello world, all you’d have seen is compiling the external crates, which of course takes a while the first time.
3
u/-Y0- Jan 02 '24
I don't remember much about Braid (after seeing The Wittness review I decided not to bother). I don't remember any bugs. However no bugs doesn't mean game isn't buggy. I never encountered bugs in Morrowind and that game had bugs up the wazoo. Plus it depends on game complexity. A hello world program will always have less bugs than a text editor.
1
u/anlumo Jan 02 '24 edited Jan 02 '24
The Witness is nowhere near a hello world program.
Also, that you had to use freaking Bethesday Games as an example speaks volumes.
Don't get me wrong, I do think that Rust is suited for game development, but I'm just careful at picking the right arguments, because he's certainly proved that it's possible to develop well running games without its restrictions on programmer freedom.
2
u/-Y0- Jan 03 '24 edited Jan 03 '24
I didn't say it is. However, Witness had way less systems and moving parts than Morrowind. A simpler game will always be easier to find and remove bugs, same way hello world will have less issues than the ORM.
What is wrong with my Bethesda example? I just used something that's a well known buggy game, that I experienced no (observable) bugs. I could have used Owl cat's Rogue Trader but it's way less notable.
Someone can write well running games in any language. Assembly and bash included. That doesn't mean it's something everyone can or should do. Rust has its pros and cons for game dev most definitely.
-1
Jan 01 '24
If by not that great you mean developing an entire programming language (with compile time features I haven't seen in other languages yet) and developing an almost production ready 3d game engine and game in it, then sure.
18
u/Minimonium Jan 01 '24
Just watch his explanation of shared/weak pointer in C++ - the guy sells air and people are eager to buy it.
14
u/anlumo Jan 01 '24
Do you mean this video?
It's the same with this video as with any other of his. He's right that using indices to vectors is bypassing the borrow checker and thus Rust doesn't provide value there directly. However, my personal take is that while he's correct that you can do the same thing in any other language with the same problems and solutions as in Rust, Rust stops you doing this in the stupid way, which is a benefit in my book.
I've also ranted (here on reddit) about people who say that using indices to vecs is an easy solution, because in the end that's just implementing your own memory allocator, with all the same issues (like accessing deallocated elements). It's just that the Rust compiler doesn't warn you about these problems, because everything is still sound if you use the component of the wrong game object, it's just not doing what you expect.
What I usually recommend is using an off-the-shelf ECS like bevy-ecs, because those do it the right way (using unsafe code most of the time). The code there wasn't any easier to write, but unlike in C++ it's easy to add such a dependency. That's one aspect that Jonathan Blow doesn't take into account, because he is the quintessential Not-Invented-Here-guy.
2
u/dpc_pw Jan 09 '24
While game developer have many valuable experiences and perspectives and one can learn this and that from them, they're tend to be very locked in their bubble and forget it's a relatively small niche. Also they receive lots of attention because games are sexy and attract following, but IMO don't deserve superstar status often attributed to them.
17
u/afonsolage Jan 01 '24
Sorry to ask, but it's a honest question: Who is Jonathan Blow? I did a quick look on Google, but haven't find anything that justify why his opinion on game dev matters.
Is he some sort of former AAA game dev or something like that?
15
Jan 01 '24
He has been in game dev for a long time and develops almost everything for his games from scratch: the programming language, his own standard library, the engine, the ui, the animation formats he uses... And while doing that he puts a lot of emphasis on high quality and performance. That is why he is well respected.
5
u/afonsolage Jan 01 '24
Ok, that's good to know, I understand why Rust isn't for him so, since he is developing his own language (Jai from what I understood), so if he uses Rust, it would break his own rule.
5
Jan 01 '24
Jai can also do a lot of compile time things, that are right now impossible in Rust. You can transformthe outputs and inputs of the compiler at various stages, which is very powerful and all happens inside of Jai. I think people will be able to reimplement the rust borrow checker in Jai if they want something like that.
But of course the language basically gives up on all of Rusts safety concepts and has different goals than Rust.11
u/v_stoilov Jan 01 '24
Jai sounds alot like Zig. With the difference that Zig is opensource and it's already been used for production.
6
u/afonsolage Jan 01 '24
Since it is closed source, I can't say much. Hope it becomes free and open source
7
u/MrCallicles Jan 01 '24
Really like his games. But all those take about programming feels like he is just trying to troll or something
-7
u/JuanAG Jan 01 '24
Well, Rust is going to happen (or other lang) because the industry it is at the edge of a cliff
Cyberpunk 2077, a 200 million €/$ which was a "fiasco" at release, really?, 200 millions and lack quality? AAA games are incredible expensive nowadays and because C++ is really complex things happens, the kind of things that dont give the customer a good experience
Cyberpunk it is not an isolated case, i cant think of a recent AAA game that was ok-ish at release, Baldurs Gate will be the closest and it had to have some hotfixes, a game that needed 9 years to release (6 to code and 3 in public beta)
C++ HUGE COMPLEXITY is the reason, you change or include some code and because you hit a corner case (or was using a "hack" that dont work because of that change) stuff that worked is now broken and the result is you get out of time forcing to release an alpha version of the game or delay forever
So Rust (or other similar tool) will happen as this cant keep going, budget cant scale much more
26
u/LeberechtReinhold Jan 01 '24
Rust wouldn't have helped with most of the Cyberpunk issues. The biggest issues came from forcing it into previous gen with huge performance issues, making objects not load in time and causing lots of problems. And like in most games, game logic tends to happen in script, which is almost always another language (lua is common, but custom langs are also used often).
It would have helped with the mem leak that happened on Act3 in BG3, for sure, and I'm sure there are several other bugs that would have been fixed in both games. But I doubt it's such a significant factor that "Rust will happen as this cant keep going".
Crunch and proper worker and project magament would have much more effect in the games industry.
9
u/augustocdias Jan 01 '24
Embark Studios are already developing stuff with rust in gaming sphere. And they’re pretty engaged with open source as well. Not sure if their recent launch (The Finals) makes use of rust though
3
u/deamon1266 Jan 01 '24
what do you think will be the initial time to market for a AAA game written in a language like rust. Considering the steep learning curve, multiple radical change in directions and staffing of new devs over time?
I could imagine that for the first years of adoption there is a significant penalty in time to market which obviously would be paid off with less bugs - at least in safe rust.
4
u/moltonel Jan 01 '24
The learning curve and staffing really isn't a problem for long projects. At $DAYJOB we're delivering/maturing our embedded code faster in Rust than in C++, even with new hires not initially knowing Rust. Might be a bit different with AAA games until engines mature, but I doubt it'll take much longer.
4
u/JuanAG Jan 01 '24
If you have to teach Rust to the team for sure it is going to be far from optimal
But Java people are not hired to code C++ after some months of training, no? It is the developer responsability to keep up in the industry as any other job, mechanics is a good example, you need to keep improving because in 70s everything used a carburator but now it is a rare thing. If you dont understand or know how inyection works you are a bad mechanic (unless you only work on that niche of old and classic cars but that it is niche and not for 99% of the rest)
We are having a real issue of lacking quality with budget that are in most cases too high, many games arent or will not be profitable, not all games are GTA or Cyberpunk
The only other option is to delay again and again the release but this again a niche aproach, if in 2015 you start coding a WoW killer and release 10 years later when MMORPG are no longer a thing is bad, you cant code a game with a window that big
Or you use Carmack aproach, you code C-ish with only a small set of C++. It works, Carmack left but the "new" Doom was a good game, it havent had mayor issues and it was coded in time (kind of) but that it is only a patch
In the 00s quality was the usual and not the exception, 25 years later is the opposite so if you keep doing things the same way it will get worst
1
u/deamon1266 Jan 01 '24
yeah, I agree about devs and industry needs to adapt and the current quality standards are already an issue.
If I understand you correctly, you would aggree that the risk developing a game for a decade is now almost unbearable. This is also kind of what I get from J. Blow - his games would not have been released if it would have taken more effort (also time I guess) making them.
So I would conclude, before the Industry shift towards new standards has not completed, the risk using that kind of technology is too high for the vast majority of studios.
2
u/Paid-Not-Payed-Bot Jan 01 '24
would be paid of with
FTFY.
Although payed exists (the reason why autocorrection didn't help you), it is only correct in:
Nautical context, when it means to paint a surface, or to cover with something like tar or resin in order to make it waterproof or corrosion-resistant. The deck is yet to be payed.
Payed out when letting strings, cables or ropes out, by slacking them. The rope is payed out! You can pull now.
Unfortunately, I was unable to find nautical or rope-related words in your comment.
Beep, boop, I'm a bot
12
u/CocktailPerson Jan 02 '24
It turns out that when most people write games as a big tangle of shared mutable state, a language that makes it hard to get things tangled and doesn't allow shared mutable state isn't great for games.