Published on

Did Mojo Just Replace Python?

  • avatar
    Tinker Assist


What is Mojo?

Mojo is a brand new programming language that is a superset of Python and is faster than python… up to 35,000x faster! Let's dig into why it was developed and what shortcomings it was built to address

Who Developed the Mojo Programming Language?

Mojo was developed by Modular, a company cofounded by Chris Lattner with a mission of "reinventing the way AI technology is developed and deployed into production". You can read more about the company and their vision on the Modular Website.

What Problems does Mojo Address?

Again, Mojo is much faster than Python. To the average Python developer, this likely doesn’t mean much (At least in my case, the speed of Python is not a limitation for the basic programs I write). However, training and running AI models is extremely computationally expensive and takes a lot of time. OpenAI, the creators of ChatGPT, have ignited the accessibility of AI to the common man, and it is well-known that the company spends on the order of a hundred thousand USD per day to run the model on servers (source). That said, Mojo directly addresses the bottlenecks in AI development and deployment today.

Mojo as a Superset of Python

What does this mean?

Mojo being a superset of Python means Mojo syntax includes all the same syntax as Python and more! Thus, your python code can be copy/pasted right over to Mojo

as of this writing, Modular's website says this is not the case yet, but it is their intent to include all the features of Python.

How is Mojo faster than Python?

Mojo is faster because of what goes on under the hood. On the Modular "Why Mojo" guide, they say:

We decided that our mission for Mojo would include innovations in compiler internals and support for current and emerging accelerators...

That is, at compile-time, your code is tailormade for the specific hardware it is to run on to optimize for speed.

So, porting existing python code over to Mojo will make it faster, but the added syntax of Mojo allows developers to really supercharge their code. This can be done through

  1. static typing of variables
  2. vectorizing of instructions through SIMD
  3. parallelization of matrix multiplication to utilize multiple compute cores simultaneously
  4. memory tiling

and more! Historically, these speed optimizations had to be done in a lower level language, often C++ - Mojo removes the need for this!

To learn more about these speed benefits and how to harness them, I encourage you to watch Jeremy Howard's Mojo Demo of the language at the Modular 2023 Project Launch Keynote

Should I use Mojo instead of Python?

If you are not currently hindered by the speed of Python, Mojo won’t really do anything for you. Mojo is in an alpha state, so no need to port your code over to a less stable language if you see little to no benefit for your current application.

How Do I Get Access to Mojo?

As of this publishing, Mojo is slowly rolling out access to the Mojo programming language. You can sign up for early access on the Modular Get Started page.

Again, Mojo is intended to be a full superset of Python... but Modular claims that even Python classes are not yet supported in the language. Thus, we likely won't see an official release of Mojo for several months.