Does the new “Mojo” programming language offer a faster superset of Python?

AI and ML Jobs


InfoWorld explores “how it resembles Python, how it differs from Python, and what it offers” for the new Mojo programming language.
The newly announced Mojo language is touted as a language that combines the multiple advantages of Python’s ease of use and clean syntax with Rust’s speed and memory safety. These are bold claims, and Mojo is still in a very early stage of development, so it will take some time before users can see for themselves how the language meets their needs. It will take. However, Mojo’s founders, a company called Modular, are offering early access. [through a limited-enrollment preview program] Online Playground: A Jupyter Notebook environment where users can run Mojo code and learn about language features and behavior…

Mojo is a “superset” of Python. Programs written in Python are valid Mojo programs, but some Python behavior is not yet implemented. At a performance cost, it is also possible to use the actual Python runtime to work with existing Python modules. When Mojo introduces new syntax, it’s for system-level programming features, primarily manual memory handling. In other words, you can write Python code (or something similar) for casual use cases, and use Mojo for more advanced, performance-oriented programming scenarios. Another big difference between Mojo and Python is that Mojo, like Python, is a runtime. Mojo is pre-compiled to machine-native code using the LLVM toolchain. To do so, you’ll get the best performance using Mojo-specific features. Python functionality is likely to come at the cost of emulating the dynamic behavior of Python, which is inherently slow, and also by using only the Python runtime.

Many of Mojo’s native language features do one of two things. These are either completely new features that don’t exist in Python at all, or extensions to Python features that offer less dynamism but better performance.
For example, Mojo has its own Hmm Keywords that define explicitly typed functions with default immutable arguments and their own arguments Structure This keyword is not a Python class, but more like its C/C++ and Rust counterparts, where “fixed layout is determined at compile time, but optimized for machine-native speed”.

But “at first glance, the code looks a lot like Python. Even the new Mojo-specific keywords integrate well with the existing Python syntax, so you can dig into the code and get a rough idea of ​​what’s going on.” You can get ideas.” And speed…
The notebook demo also shows examples of how to speed up Mojo code through parallelism, vectorization, and “tiling” (improving cache locality of operations). One of the demos, the 128×128 matrix multiplication demo, ran 17x faster than Python (using the Python runtime from Mojo playground) without any special modifications. Mojo delivers 1866x speedup by adding type annotations, 8500x speedup by adding vectorized operations, and 15000x speedup by adding parallelization.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *