#381 克里斯·拉特纳:编程与 AI 的未来

#381 – Chris Lattner: Future of Programming and AI

第 381 期··嘉宾 / 主题:克里斯·拉特纳·文稿
官方音频00:00 / --:--
下载 MP3
#381 克里斯·拉特纳:编程与 AI 的未来▶ 播放视频
文稿由本站用 Qwen3-ASR(基于官方发布音频)机器转写,可能有识别错误,人名与数字请以音频为准。
Lex Fridman Podcast #381 - #381 – Chris Lattner: Future of Programming and AI Machine transcription by Qwen3-ASR 0.6B (MLX, local, Apache-2.0). May contain recognition errors. The following is a conversation with Chris Latner, his third time on this podcast. As I've said many times before, he's one of the most brilliant engineers in modern computing, having created LLM compiler infrastructure project, the clang compiler, the Swift programming language, a lot of key contributions to TensorFlow and TPU's as part of Google. He served as vice president of autopilot software at Tesla. Was a software innovator and leader at Apple, and now he co-created a new full stack AI infrastructure for distributed training, inference, and deployment on all kinds of hardware called Modular and a new programming language called Mojo that is a superset of Python, giving you all the usability of Python but with the performance of C C plus plus. In many cases, Mojo code has demonstrated over thirty thousand X speedup over Python. If you love machine learning, if you love Python, you should definitely give Mojo a try. This programming language, this new AI framework and infrastructure, and this conversation with Chris is mind blowing. I love it. It gets pretty technical at times, so I hope you hang on for the ride. And now a quick few second mention of each sponsor. Check them out in the description. It's the best way to support this podcast. We got iHerb for health, Numai for world's hardest data science tournament, and Inside Tracker for tracking your biological data. Choose wisely, my friends. Also, if you want to work with our team, our amazing team, we're always hiring. Could Alex Friedman dot com slash hiring. And now onto the full ad reads. As always, no ads in the middle. I try to make this interesting, but if you skip them, if you must, my friends, please still check out the sponsors. I enjoy their stuff, maybe you will too. This show is brought to you by iHerb, a platform, a website, a place we can go and get high quality selected just for you health and wellness products. For great value, inexpensive, affordable. I get fish oil over there. It's one of the main supplements I've taken for a long, long, long time in pill form. Makes me feel like I'm oiling the machine that is the human body and the human mind. Even just saying that makes me wonder what is the power of the placebo effect in all of this. I'm actually a big believer in the power of the human mind, coupled with the effectiveness of medication and supplements and nutrition and diet and exercise. All of it. If you couple the belief that the thing will work with stuff that actually works. It's like a supercharge. It's the mind. There's something about the mind allowing the thing to work. And maybe the belief that it works reduces stress and has kind of secondary and tertiary effects that you can't even comprehend on the entirety of the biological system that is the human body. It's so fascinating and it's so difficult to do good studies on that. Because the whole point is, you want to study the effect of the entirety of the lifestyle and diet decisions you make on the entirety of the human organism—the billions of organisms that make up a single organism that is you. Anyway, get 22% off with promo code Lex when you go to iHerb dot com slash Lex. This show is also brought to you by Numai, a hedge fund that uses AI and machine learning to make investment decisions. They created a tournament, a challenge for all machine learning gurus to come and to compete against each other. To build the best predictive models for financial markets, the stakes are high. This is the kind of problems in the machine learning space that I really care about—real world problems with high stakes, not toy problems, not ImageNet. Now ImageNet and all that kind of stuff is good for exploring little ideas, the nuances of architectures, training procedures, of. Cool little ideas of the entirety of the pipeline of how to do machine learning, or for education purposes. But if you want to really develop ideas that work in the real world, you should be working on real world data where the stakes are high. And this is probably one of the hardest tournaments for machine learning in the world. Head over to numai dot com slash lex to sign up for a tournament and hone your machine learning skills. That's numai dot com slash lex for a chance to play against me and win a share of the tournament prize pool. This show is also brought to you by Inside Tracker, a service I use to track biological data. As I was saying, the entirety of the biological organism that is you—the individual cells, all the life force that makes up the details of the cells and the proteins. And the blood and the organs and the individual systems that are interconnected to each other in these incredible complex ways that are all asynchronously communicating with each other through chemistry, through physics, through electrical signals, through mechanical signals, through whatever the hell signals that I can't even find the right words for. It's an incredible system. How is it possible that this thing works at all? I'm looking out into the distance now as I say these words and my visual cortex is processing all of it and somehow makes sense of all of it. This is incredible. Anyway, measuring data on this incredible organism is good. And companies that allow you to measure it in order to make lifestyle decisions is obviously the future. That's why I support Inside Tracker. You can get special savings for a limited time when you go to insidetracker dot com slash lex. This is the Lex Friedman podcast to support it. Please check out our sponsors in the description. And now your friends here's Chris Latner. It's been I think two years since we last talked, and in that time you somehow went and co-created a new programming language called Mojo. So it's optimized for AI. It's a superset of Python. Let's look at the big picture. What is the vision for Mojo? For Mojo, well, so I mean I think you have to zoom out. So I've been working on a lot of related technologies for many many years. So I've worked on LLM and a lot of things and mobile and servers and things like this. But the world's changing, and what's happened with AI is we have new GPUs and new machine learning accelerators and other ASICs and things like that that make AI go real fast. At Google, I worked on TPU's. That's one of the biggest, largest scale deployed systems that exist for AI. And really, what you see is if you look across all of the things that are happening in the industry, there's this new compute platform coming, and it's not just about. CPUs or GPUs or TPU's or NPU's or IPU's or whatever all the PUs, right? It's about how do we program these things, right? And so for software folks like us, right, it doesn't do us any good if there's this amazing hardware that we can't use. And one of the things you find out really quick is that having the theoretical capability of programming something and then having the world's power and the innovation of all the all the smart people in the world get unleashed on something can be quite different. And so really, where Mojo came from was starting from a problem of we need to be able to take machine learning, take the infrastructure underneath it and make it way more accessible, way more usable, way more understandable by normal people and researchers and other folks that are not themselves like experts in GPUs and things like this. And then through that journey, we realized, hey, we need syntax for this, we need to program language. So one one of the the main features of the language, I say so fully in jest, is that it allows you to have the file extension to be an emoji or the fire emoji, which is. One of the first emojis used as a file extension I've ever seen in my life, and then you ask yourself the question, "Why in the 21st century are we not using Unicode for file extensions?" I mean it's an epic decision. I think clearly the most important decision in the most, but you could also just use Mojo as the file extension. Well, so okay, so take a step back. I mean, come on, Lex, do you think that the world's ready for this? This is a big moment in the world, right? This is we're releasing this onto the world. This is innovation. I mean, it really is kind of brilliant. Emoji is such a big part of our daily lives. Why isn't it not in programming? Well, and and like you take a step back and look look at what file extensions are, right? They're basically metadata, right? And so why are we spending all the screen space on them and all the stuff? Also, you know you have them stacked up next to text files and PDF files and whatever else. Like if you're going to do something cool, you want to stand out, right? Emojis are colorful, they're visual, they're beautiful. What's been the response so far? From is there support on like Windows on operating system in displaying like file explorer? Yeah, the one problem I've seen is that Git doesn't escape it right, and so it thinks that the fire emoji is unprintable and so it like prints out weird hex things if you use the command line Git tool. But everything else, as far as I'm aware, works fine. And I have faith that Git can be improved, so I'm not Git Hub is fine. Git Hub is fine, yeah, Git Hub is fine, Visual Studio Code, Windows, like all the stuff totally ready because people have internationalization in their normal part of their path. So this is just like taking the next step, right? Somewhere between, oh wow, that makes sense, cool. I like new things too. Oh my god, you're killing my baby! Like what are you talking about? This can never be like I can never handle this. How am I going to type this? Like all these things, and so this is something where I think that the world will get there. We don't have to bet the whole farm on this. I think we can provide both paths, but I think it'll be great. When can we have emojis as part of the code? I wonder. Yeah, so I mean lots of languages provide that. So I think that we have partial support for that. It's probably not fully done yet, but but yeah, you can you can do that. For example, in Swift, you can do that for sure. So example we give gave it Apple was the the dog cow. Yeah, so that's a classical Mac heritage thing, and so use the dog and the cow emoji together and that could be your variable name. But of course, the internet went and made pile of poop for everything. Yeah, so you know if you want to name your function pile of poop, then you can totally go to town and see how that gets through code review. Okay, so let me just ask a bunch of random questions. So is Mojo primarily designed for AI's or is it a general purpose programming language? Good question. So it's AI first, and so AI is driving a lot of the requirements. And so Modular is building and designing and driving Mojo forward, and it's not because it's an interesting project theoretically to build. It's because we need it. And so Modular, we're really tackling the AI infrastructure landscape and the big problems in AI and the reasons that it is so difficult to use and scale and adopt and deploy and like all these big problems in AI. And so we're coming at it from that perspective. Now, when you do that, when you start tackling these problems, you realize that the solution to these problems isn't actually an AI specific solution. And so while we're doing this, we're building Mojo to be a fully general programming language, and that means that you can obviously tackle GPUs and CPUs and like these AI things, but it's also a really great way to build. Numai and other things like that, or you know just if you look at what many Python libraries are today, often there's a layer of Python for the API and they end up being C and C plus plus code underneath them. That's very true in AI, that's true in lots of other demands as well. And so anytime you see this pattern, that's an opportunity for Mojo to help simplify the world and help people have one thing. Optimized through simplification by having one thing. So you mentioned Modular Mojo is the programming language, Modular is the whole software stack. So just over a year ago, we started this company called Modular. Yeah, okay. What Modular's about is it's about taking AI and upleveling it into the next generation, right? And so if you take a step back, what's gone on in last five, six, seven, eight years is that we've had things like TensorFlow and PyTorch and these other systems come in. You've used them, you know this, and what's happened is these things have grown like crazy. They get tons of users. It's in production deployment scenarios. It's being used to power so many systems. I mean AI is all around us now. Now it used to be controversial years ago, but now it's a thing. But the challenge with these systems is that they haven't always been thought out with current demands in mind. And so you think about it when where were LLMs eight years ago? Well, they didn't exist, right? AI has changed so much, and a lot of what people are doing today are very different than when these systems were built. And meanwhile, the hardware side of this has gone into a huge mess. There's tons of new chips and accelerators, and every every big company's announcing a new chip every day. It feels like, and so between that you have like moving system on one side, moving system on the other side, and it just turns into this gigantic mess, which makes it very difficult for people to actually use AI, particularly in production deployment scenarios. And so what Modular's doing is we're helping build out that software stack, help solve some of those problems, so then people can be more productive and get more AI research into production. Now what Mojo does is it's a really really really important piece of that, and so that is you know part of that engine and part of the technology that allows us to solve these problems. So Mojo is a programming language that allows you to do the high level programming, the low level programming, like do all kinds of programming. In that spectrum that gets you closer and closer to the hardware. So take a step back, so Lex. What do you love about Python? Oh boy, where do I begin? What is love? What do I love about Python? You're guy who knows love. I know this. Yes, how intuitive it is. How it feels like I'm writing natural language English. How when I can not just write but read other people's code somehow I can understand it faster. It's more condensed than other languages like ones I'm really familiar with like C plus plus. And C, there's a bunch of sexy little features. Yeah, we probably talk about some of them, but list comprehensions and stuff like this. Also, and and don't forget the entire ecosystem of all the packages. Oh yeah, that's probably huge. Because there's always something if you want to do anything, there's always a package. Yeah, so it's not just the ecosystem of the packages and the ecosystem of the humans that do it. That that's a really that's an interesting dynamic. Because I think something about the the usability and the ecosystem makes the thing viral. It grows and then it's a virtuous cycle. I think. Well, and there's many things that went into that. Like so, I think that ML was very good for Python, and so I think that TensorFlow and PyTorch and these systems embracing Python really took and helped Python grow. But I think that the major thing underlying it is that Python's like the universal connector. Right, it really helps bring together lots of different systems so you can compose them and build out larger systems without having to understand how it works. But then what is the problem with Python? Well, I guess you could say several things, but probably that it's slow. I think that's usually what people complain about, right? And so slow. I mean, other people complain about tabs and spaces versus curly braces or whatever, but I mean those people are just wrong because it is actually just better to use indentation. Wow, strong words. So actually, I'm a small tangent. Let's actually take that. Let's take all kinds of tangents. Oh come on, Lex, you can push me on it. I can take design design. Listen, I recently left Emacs for VS Code, and the kind of hate mail I had to receive because on the way to doing that I also said I've considered Vim. Yep, and chose not to and went with VS Code and just touching on deep religions, right? Anyway, tabs is an interesting design decision, and so you really written a new programming language here. Yes, it is a a superset of Python, but you can make a bunch of different interesting decisions here. Totally, yeah, and you chose actually to stick with Python as a. In terms of some of the syntax, well, so let me explain why, right? So I mean, you can explain this in many rational ways. I think that the indentation is beautiful, but that's not a rational explanation, right? So, but I can defend it rationally, right? So first of all, Python One has millions of programmers. Yeah, it is huge. It's everywhere. It owns machine learning, right? So factually, it is the thing, right? Second of all, if you look at it, C code, C plus plus code, Java, whatever Swift, curly brace languages, also run through formatting tools and get indented. And so if they're not indented correctly, first of all, we'll twist your brain around, it can lead to bugs. There's notorious bugs that have happened across time where the indentation was wrong or misleading and it wasn't formatted right, and so it turned into an issue, right? And so what ends up happening in modern large scale code bases is people run automatic formatters. So now what you end up with is indentation and curly braces. Well, if you're going to have you know the notion of grouping, why not have one thing, right? And get rid of all the clutter and have a more beautiful thing, right? Also, you look at many of these languages, it's like okay, well you can have curly braces or you can omit them if there's one statement or you just like enter this entire world of complicated design space that. Objectively, you don't need if you have Python style indentation. So yeah, I would love to actually see statistics on errors made because of indentation, like how many errors are made in Python versus in C plus plus that have to do with basic formatting all that kind of stuff. I'd love to see. I think it's it's probably pretty minor because once you get like you use VS Code I do too. So if you get VS Code setup, it does the indentation for you generally, right? And so you don't you know it's actually really nice to not have to fight it, and then what you can see is the editor is telling you how your code will work by indenting it, which I think is pretty cool. I honestly don't think I've ever I don't remember having an error in Python because I indented stuff wrong. So I mean I think that there's again this is a religious thing, and so I can joke about it and I love I love to kind of you know I realize that this is such a polarizing thing and everybody wants to argue about it, so I like poking at the bear a little bit, right? But but frankly, right come back to the first point Python One like it's huge, it's an AI, it's the right thing for us. Like we see Mojo as being an incredible part of the Python ecosystem. We're not looking to break Python or change it or quote unquote fix it. We love Python for what it is. Our view is that Python is just not done yet. And so if you look at you know you mentioned Python being slow, well there's a couple of different things that go into that which we can talk about if you want. But one of them is it just doesn't have those features that you would use to do C like programming. And so if you say okay, well I'm forced out of Python into C for certain use cases. Well then what we're doing is we're saying okay well why why is that can we just add those features that are missing from Python back up to Mojo and then you can have everything that's great about Python all the things you are talking about that you love plus not be forced out of it when you do something a little bit more computationally intense or weird or hardwarey or whatever it is that you are doing well a million questions I want to ask what high level again is it compiled or is it an interpreter language so Python is just in time compilation what's what's Mojo so Mojo a complicated answer does all the things so it's interpreted it's JIT compiled and it's statically compiled um and so this is for a variety of reasons um so one of the things that makes Python beautiful is that it's very dynamic and because it's dynamic one of the things they added is that it has this powerful meta programming feature and so if you look at something like PyTorch or TensorFlow or or um I mean even a simple simple use case like you define a class that has the plus method right you can overload the Dunder methods like Dunder add for example and then the plus method works on your class and so it has very nice and very expressive dynamic meta programming features in Mojo we want all those features come in like we don't want to break Python we want it all to work but the problem is is you can't run those super dynamic features on an embedded processor or on a GPU right or if you could you probably don't want to just because of the performance and so we entered this question of saying okay how do you get the power of this dynamic meta programming into a language that has to be super efficient in specific cases and so what we did was we said okay we'll take that interpreter Python has an interpreter in it right take that interpreter and allow it to run it compile time and so now what you get is you get compile time meta programming and so this is super interesting super powerful because one of the big advantages you get is you get Python style expressive APIs you get the ability to have overloaded operators and if you look at what happens inside of like PyTorch for example with automatic differentiation and eager mode like all these things they're using these really dynamic and powerful features at runtime but we can take those features and lift them so they run at compile time so you're because C plus plus has meta programming with with templates but it's really messy it's super messy it's it's always it was accidentally I mean different people have different interpretations my interpretation is that it was made accidentally powerful it was not designed to be Turing complete for example but that was discovered kind of along the way accidentally um and so there have been a number of languages in the space and so they usually have templates or code instantiation code copying features of various sorts um some more modern languages or some more newer languages let's say like you know they're fairly unknown like Zig for example says okay well let's take all of those types you can run it all those things you can do at runtime and allow them to happen at compile time and so one of the problems with C plus plus I mean which is one of one of the problems with C plus plus there we go is wrong words we're going to offend everybody too that's okay I mean everybody hates me for a variety of reasons anyways I am sure right I've written enough the way they show love I have written enough C plus plus code to earn a little bit of grumpiness with C plus plus but um but one of the problems with it is that the meta programming system templates is just a completely different universe from the normal runtime programming world and so if you do meta programming and programming it's just like a different universe different syntax different concepts different stuff going on and so again one of our goals with Mojo is to make things really easy to use easy to learn and so there is a natural stepping stone and so as you do this you say okay well I have to do programming at runtime after programming at compile time why are these different things how hard is that to pull it out because that sounds to me as a fan of meta programming in C plus plus even how how hard is it to pull that off that sounds really really exciting because you can do the same style programming at compile time and at runtime that's really really exciting and so I mean in terms of the compiler implementation details it's hard I won't be shy about that it's super hard it requires I mean what Mojo has underneath the covers is a completely new approach to the design of the compiler itself and so this builds on these technologies like MLIR that you mentioned that also includes other like caching and other interpreters and JIT compilers and other stuff like you have like an interpreter inside the within the compiler yes and so it really takes the standard model of programming languages and kind of twists it and unifies it with the runtime model right which I think is really cool and to me the value of that is that again many of these languages have meta programming features like they grow macros or something right list right I know your roots right you know and this is a powerful thing right and so you know if you go back to list one of the most powerful things about is that it said that the meta programming and the programming are the same right and so that made it way simpler way more consistent way easier to understand reason about and it made it more composable so if you build a library you can use it both at runtime and compile time which is pretty cool yeah and and for machine learning I think meta programming I think we could generally say is extremely useful and so you you get features I mean I'll jump around but there is the feature of auto tuning and adaptive compilation just blows my mind well so okay so let's come back to that all right so so what what is what is what is machine learning like what is a machine learning model like you take a PyTorch model off the internet right um it's really interesting to me because what a what PyTorch and what TensorFlow and all these frameworks are kind of pushing compute into is they're pushing into like this abstract specification of a compute problem which then gets mapped in a whole bunch of different ways right and so this is why it became a meta programming problem is that you want to be able to say cool I have I have this neural net now run it with batch size a thousand right do do do a mapping across batch or okay I want to take this problem now running across a thousand CPUs or GPUs right and so like this this problem of like describe the compute and then map it and do things and transform it or or like actually it's very profound and that's one of the things that makes machine learning systems really special maybe can you describe auto tuning and how do you pull off I mean I guess adaptive compilation is what we're talking about as meta programming how do you pull off auto tuning I mean is that is that as profound as I think it is it seems like a really like you know we mentioned list comprehensions to me from a quick glance at Mojo which by the way I have to absolutely like dive in as I realize how amazing this is I absolutely must dive in that looks like just an incredible feature for machine learning people yeah well so so what is auto tuning so take a step back auto tuning is a feature in Mojo it's not so very very little of what we're doing is actually research like many of these ideas have existed in other systems in other places and so what we're doing is we're pulling together good ideas remixing them and making them into a hopefully a beautiful system right and so auto tuning the observation is that turns out hardware systems algorithms are really complicated turns out maybe you don't actually want to know how the hardware works right a lot of people don't right and so there are lots of really smart hardware people I know a lot of them where they know everything about okay the the cache size is this and the number of registers is that and if you use this what length of vector it's going to be super efficient because it maps directly onto what it can do and like all this kind of stuff or the GPU has SMs and it has a warp size of whatever right all this stuff that goes into these things or the tile size of a TPU is one twenty eight like these these factoids right my belief is that most normal people and I love hardware people also I am not trying to offend literally everybody in the internet but most programmers actually don't want to know this stuff right and so if you come at it from the perspective of how do we allow people to build both more abstracted but also more portable code because you know could be that the vector length changes or the cache size changes or it could be that the tile size of your matrix changes or the number you know an A100 versus an H100 versus a Volta versus a whatever GPU have different characteristics right a lot of the algorithms that you run are actually the same but the parameters these magic numbers you have to fill in end up being really fiddly numbers that an expert has to go figure out and so what auto tuning does is says okay well guess what there is a lot of compute out there right so instead of having humans go randomly try all the things or do a grid search or go search some complicated multidimensional space how about we have computers do that right and so what auto tuning does is you can say hey here is my algorithm if it's a a matrix operation or something like that you can say okay I'm going to carve it up into blocks I'm going to do those blocks in parallel and I want this this with one hundred twenty eight things that I'm running on I want to cut it this way or that way or whatever and you can say hey go see which one's actually empirically better on the system and then the result of that you cache for that system you save it and so come back to twisting your compiler brain right so not only does the compiler have an interpreter that uses to do meta programming that compiler that interpreter that meta programming now has to actually take your code and go run it on a target machine see see which one it likes the best and then stitch it in and then keep going right so part of the compilation is machine specific yeah well so I mean this is an optional feature right so you don't have to use it for everything but yeah if if you're so one one of one of the things that we're in the quest of is ultimate performance yes right ultimate performance is important for a couple of reasons right so if you are an enterprise you are looking to save costs and compute and things like this ultimate performance translates to you know fewer servers like if you care about the environment hey better performance leads to more efficiency right I mean you could joke and say like you know Python is bad for the environment right and so if you move to Mojo it's like at least tenx better just out of the box and keep going right um but but performance is also interesting because it leads to better products and so in the space of machine learning right if you reduce the latency of a model so it runs faster so every time you query the server running the model it takes less time well then the product team can go and make the model bigger well that actually makes it so you have a better experience as a customer and so a lot of people care about that so for auto tuning for like tile size you mentioned one twenty eight for TPU you would specify like a bunch of options to try just in the code just simple statement and then you can just set and forget and know depending wherever it compiles it'll actually be the fastest and yeah exactly and the beauty of this is that it helps you in a whole bunch of different ways right so if you are building so often what will happen is that you know you've written a bunch of software yourself right you you wake up one day you say I have an idea I'm going to go cut up some code I get to work I forget about it I move on with life I come back six months or a year or two years or three years later you dust it off and you go use it again in a new environment and maybe your GPU is different maybe you are running on a server instead of a laptop maybe whatever right and so the problem now is you say okay well I mean again not everybody cares about performance but if you do you say okay well I want to take advantage of all these new features I don't want to break the old thing though right and so the typical way of handling this kind of stuff before is you know if you are talking about C plus plus templates or you are talking about C with macros you end up with if defs you get like all these weird things get layered in make the code super complicated and then how do you test it right becomes this this crazy complexity multidimensional space you have to worry about and you know that just doesn't scale very well actually let me just jump around before I go to some specific features like the increase in performance here that we're talking about can be just insane you write that Mojo can provide a thirty five thousand x speed up over Python how does it do that yeah so you can even do more but we'll get to that so so first of all when we say that we're talking about what's called C Python it's the default Python that everybody uses when you type Python three that's like typically the one you use right C Python is an interpreter and so interpreters they have an extra layer of like byte codes and things like this that they have to go read parse interpret and it makes them kind of slow from that perspective and so one of the first things we do is we move to a compiler and so just moving to a compiler getting the interpreter out of the loop is two to five to tenx speed up depending on the code so just out of the gate just using more modern techniques right now if you do that one of the things you can do is you can start to look at how C Python started to lay out data and so one of the things that that C Python did and this isn't part of the Python spec necessarily but this is just sets of decisions is that if you take an integer for example it'll put it in an object because in Python everything is an object and so they do the very logical thing of keeping the memory representation of all objects the same so all objects have a header they have like payload data and and what this means is that every time you pass around an object you are passing around a pointer to the data well this has overhead right turns out that modern computers don't like chasing pointers very much and things like this it means that you have to allocate the data means you have to reference count it which is another way that Python uses to keep track of memory and so this has a lot of overhead and so if you say okay let's try to get that out of the heap out of a box out of an indirection and into the registers that's that's another tenx so it adds up if you if you are reference counting every single every every single thing you create that adds up yeah and if you look at you know people complain about the Python gil this is one of the things that hurts parallelism that's because of the reference counting right and so the gil and reference counting are very tightly intertwined in Python it's not the only thing but it's very tightly intertwined and so then you lean into this and you say okay cool well modern computers they can do more than one operation at a time and so they have vectors what is a vector well a vector allows you to take one instead of taking one piece of data doing an add or a multiply and then pick up the next one you can now do a four or eight or sixteen or thirty two at a time right well Python doesn't expose that because of reasons and so now you can say okay well you can adopt that now you have threads now you have like additional things like you can control memory hierarchy and so what Mojo allows you to do is it allows you to start taking advantage of all these powerful things that have been built into the hardware over time and it gives the library gives very nice features so you can say just parallelize do this in parallel right so it's very very powerful weapons against slowness which is why people have been I think having fun like just taking code and making it go fast because it's just kind of an adrenaline rush to see like how fast you can get things before I talk about some of the interesting stuff with parallelization all that let's let's first talk about like the basics we talk to indentation right so this thing looks like Python it's sexy and beautiful like Python as we mentioned is it a typed language so what's the role of types yeah good question so Python has types it has strings it has integers it has dictionaries and like all that stuff but they all live at runtime right and so because all those types live at runtime in Python you never you don't have to spell them Python also has like this whole typing thing going on now and a lot of people use it yeah I am not talking about that that's that's kind of a different thing we can go back to that if you want but but typically the you know you just say I take I have a def and my def takes two parameters I am going to call them a and b and I don't have to write a type okay so that is great but what that does is that forces what's called a consistent representation so these things have to be a pointer to an object with the object header and they all have to look the same and then when you dispatch a method you go through all the same different paths no matter what the the receiver whatever that type is so what Mojo does is it allows you to have more than one kind of type and so what it does is allows you to say okay cool I have I have an object and objects behave like Python does and so it's fully dynamic and that's all great and for many things classes like that's all very powerful and very important but if you want to say hey it's an integer and it's thirty two bits or it's six four bits or whatever it is or it's a floating point value and it's six four bits well then the compiler can take that and it can use that to do way better optimization and turns out again getting rid of the indirections it's huge means you can get better code completion because you have because compiler knows what the type is and so it knows what operations work on it and so that's actually pretty huge and so what Mojo does is allows you to progressively adopt types into your program and so you can start again it's compatible with Python and so then you can add however many types you want wherever you want them and if you don't want to deal with it you don't have to deal with it right and so one of one of you know our opinions on this is that it's not that types are the right thing or the wrong thing it's that they're a useful thing wait so it's kind of optional it's not strict typing you don't have to specify a type exactly okay so it's starting from the thing that Python is kind of reaching towards right now with

本集资源与出处