Mojo Lang… a fast futuristic Python alternative

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
it is May 4th 2023 and you are watching the code report python is a wonderful language for productive programming but it has one big problem it's too slow and going slow means you'll get made fun of by the rust and C plus Chads of the world but the tables are about to turn thanks to a brand new programming language called Mojo a superset of python that's not just two times faster not ten times faster but up to 35 000 times faster than your grandpa's Python and that's a huge deal because Python's the dominant language for artificial intelligence but behind the curtain anything that needs to go fast is written in C or C plus plus in today's video we'll take Mojo for a spin but first here are five things that you need to know about it one this is not some random guy's side project on GitHub but rather it comes from a company founded by Chris lattner the guy who created the Swift programming language and the llvm compiler tool chain if anybody could fix Python's problems it's him and if you have no idea what llvm is check out this video two it's a language designed for programming on AI Hardware like gpus running Cuda and other accelerators it achieves this by Leverage multi-level intermediate representation to scale to Exotic Hardware types without a ton of complexity and it even has built-in Auto tuning to optimize your code for your Target Hardware three it's designed as a super set of python in the same way typescript is a superset of JavaScript so you don't need to learn another language to take advantage of it and this is unique compared to other modern systems languages like rust Zig Nim and so on which would have a higher learning curve for existing python programmers it does have a bunch of features on top of python like VAR and Lut declarations and structs but the base language is fully compatible with python and it can also interop with the python ecosystem which means you can still use your favorite libraries like numpy pandas Etc or it adds strong type checking to the language you can still use Dynamic types if you prefer but static types are essential for optimized performance and error checking for memory management it has an ownership system and borrow Checkers similar to rust and also supports manual memory management with pointers like C plus plus it's a pragmatic language that gives you safety but also the flexibility to be unsafe when needed now the final thing to know is that currently it's not available to the public it's still in very early development it will be open sourced in the future but currently there is a wait list to try it out I was lucky enough to get Early Access so let's fire it up to run it you can create a file ending in dot Mojo or dot fire Emoji that's a huge advantage over python which doesn't allow you to name your files in dot snake but we can also run the code in a Jupiter notebook where it behaves like an interpreted language here we have a matrix multiplication demo that computes a DOT product to demonstrate the crazy performance gains we get with Mojo first it benchmarks a basic function in Python then by simply importing that code into Mojo it's executed 14 times faster with no modifications to the code but we're only just getting started we can further optimize this code by adding types to the python implementation Mojo allows us to do that with its built-in struct keyword a struct is very similar to a python class but structs are static unlike classes which are Dynamic inside this truck we ALS have keywords like VAR and let which can Define mutable and immutable variables and Def is replaced with FN which is a stricter type type of function also notice single instruction multiple data which is a built-in type that represents a vector where a single instruction can be executed across multiple elements in parallel on the underlying Hardware once we have this struct we can then use it as a type in the python implementation then when we Benchmark the code again we get a ridiculous 500x performance boost but we're still not happy yet in the Inner Loop we can query the vector width instead of hard coding it and that gives us a thousand X gain but that's nothing compared to what we're about to do linear algebra is perfect for parallel Computing and we can easily make our code multi-threaded with the built-in parallelized function increasing our speed buff to 2000x but now I've got a fever and the only prescription is more performance luckily Mojo has built-in tiling utilities that basically allow us to cache and reuse data more efficiently and we can even auto-tune it to find the optimal parameters for our Hardware the end result is over four thousand times faster execution compared to the original python code that's pretty crazy and if you want to see this code broken down in Greater detail I'd highly recommend this video from Jeremy Howard but I'm curious is what you guys think do you really think Mojo could kill Python and C plus at the same time I'm a bit skeptical but employers are already hiring Mojo developers with 10 years of experience this has been the code report thanks for watching and I will see you in the next one [Music]
Info
Channel: Fireship
Views: 737,958
Rating: undefined out of 5
Keywords: webdev, app development, lesson, tutorial
Id: V4gGJ7XXlC0
Channel Id: undefined
Length: 4min 14sec (254 seconds)
Published: Thu May 04 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.