Why is Mojo's dictionary slower (!) than Python's?

  Рет қаралды 3,947

EKB PhD

EKB PhD

6 ай бұрын

Seriously, I don't know why. Leave a comment with feedback on my Mojo script.
Take a look at my Mojo script here:
github.com/ekbrown/scripting_...
And here's my Python script:
github.com/ekbrown/scripting_...
Here's the Mojo language:
www.modular.com/max/mojo
BTW: I used the Elgato Wave 3 microphone in this video:
www.elgato.com/us/en/p/wave-3...
Here's a follow-up video in which a hand-written hashmapdict in Mojo (thanks to Maxim Zaks!) that is faster than Python's dictionary:
• Mojo hand-written hash...
#mojolang #python

Пікірлер: 29
@hyperplano
@hyperplano 4 ай бұрын
In the discord channel I read the current dictionary implementation is not optimized. It's been included to allow developers to experiment more with the language, but it will be optimized in future releases.
@earlkjarbrown3753
@earlkjarbrown3753 4 ай бұрын
Great to hear! Thanks for pointing this out.
@ekbphd3200
@ekbphd3200 4 ай бұрын
Thanks!
@brendanhansknecht4650
@brendanhansknecht4650 4 ай бұрын
Python actually has a realy optimized dictionary for its constraints (taking untyped keys and values). Mojo will catch up (and should surpass due to static types), but the current dict is new and mostly unoptimized. Also, this should be memory bound instead of compute bound so even in the long term, I would not expect much of a difference.
@ekbphd3200
@ekbphd3200 4 ай бұрын
Yeah, good points. Thanks.
@androth1502
@androth1502 4 ай бұрын
my guess would be that the mojo implementation is a quick lazy thing just to get maps in, while python uses a C implementation.
@ekbphd3200
@ekbphd3200 4 ай бұрын
Yeah, I assume that's what's going on.
@androth1502
@androth1502 4 ай бұрын
@@ekbphd3200 still not a good look for them to release something so unoptimized after boldly claiming to be thousands of times faster than python. lol.
@svenmasche
@svenmasche 3 ай бұрын
lmao up until minute 9 i was expecting that you were going to explain it ^^
@ekbphd3200
@ekbphd3200 3 ай бұрын
Sorry. I'm curious to see when they will be able to optimize the native Mojo dictionary. In the meantime, there's a third-party Mojo dictionary that is faster. Take a look at this video: kzbin.info/www/bejne/d6KneJ5_p6lsn9Usi=xx6_7G-srSQX3KjF
@murithiedwin2182
@murithiedwin2182 2 ай бұрын
Mojo official benchmark with python performance needs a comprehensive "mojo feature to python feature" comparison benchmark... We would like then to see where the 35,000X speed up claim came from...
@ekbphd3200
@ekbphd3200 2 ай бұрын
Yeah, I think the specific task is important. As a linguist, I use strings a lot, and Python still seems to be faster than Mojo right now. I hope Mojo becomes faster than Python with strings at some point in the future. Thanks for the comment!
@niks660097
@niks660097 Ай бұрын
@@ekbphd3200 The thing is in python is a lot of string operations are handled by pure C code, for example regex is completely done by a FSM in C, that's why regexes in python are faster than java, golang you name it, if the string you are searching on is big enough, in my current company we were planning to move some code from python to golang cause of performance issues, but while profiling, python's string regexes and dict's perf. caught everyone off guard.
@sillybuttons925
@sillybuttons925 4 ай бұрын
The script does exercise item lookup, looping etc. So seems like a pretty valid comparison. Maybe try the collections.Counter if it's implemented in mojo?
@ekbphd3200
@ekbphd3200 4 ай бұрын
The hashmapdict is quick, as is the compact dict, written by a third party guy: github.com/mzaks/compact-dict kzbin.info/www/bejne/d6KneJ5_p6lsn9U
@jinsongli3128
@jinsongli3128 2 ай бұрын
my test with the List also shows mojo is slower than python, not sure if I did anything wrong.
@ekbphd3200
@ekbphd3200 2 ай бұрын
Thanks for that info! Yeah, I assume that at some point Mojo will be faster than Python with most tasks but that’s not the case yet with the linguistic tasks I do most often.
@cmdlp4178
@cmdlp4178 2 ай бұрын
Maybe in Mojo the Strings are copied and reallocated as new objects, maybe because of the different StringKey type, or maybe (I am not as familiar with Mojo) because Dict stores and owns an own instance of the string, similar to as in C++. There the string and the memory associated with the string is "owned" by e.g. the unordered_map. Maybe you should retry measuring the time, now inserting floating point numbers for examples, that might not be allocated in Mojo.
@ekbphd3200
@ekbphd3200 2 ай бұрын
Good idea! I'll give that a try soon.
@indibarsarkar3936
@indibarsarkar3936 Ай бұрын
Please try splitting the data in half and assigning each halves to a dictionary. Then measure the time taken to copy or interchange elements from one dictionary to another. Maybe the problem is in the file management and not in dictionary!!
@ekbphd3200
@ekbphd3200 Ай бұрын
Mojo's dictionary has increased in performance (when inserting items) with v24.4. I found a 4x increase in speed with a particular linguistic task. Take a watch: kzbin.info/www/bejne/kKGoi2iwgrtkjtU
@pe6649
@pe6649 5 ай бұрын
Sorry, but the answer is mostly: It does simply not make sense to do benchmark comparisons with a language or tool under development. Mojo is under development. It is not at all astounding, what you found out. To me it is more astounding that you are surprised. Performance is always about details! Simple expectations like x is faster than y fail VERY often when measured. Take the various steps to make Python faster we absolved in the last decade and more: For exampe- In Python 3.11 at first JIT compiling was added. You can fasten something up, but it is not a nobrainer, and further optimizations are needed and will come. I believe Mojo will do a good job finally. But be a bit more patient. Especially Mojo will shine in optimizing for new hardware architectures. If you just want fast Python, use Numba or Nuitka..
@earlkjarbrown3753
@earlkjarbrown3753 4 ай бұрын
Yeah, good points. I've enjoyed watching Mojo as it's being developed and assume it will be smokingly fast in comparison to Python in nearly all applications at some point in the future.
@ekbphd3200
@ekbphd3200 4 ай бұрын
Thanks!
@talhatahir4931
@talhatahir4931 2 ай бұрын
lol!!! Those mojicians claim that they are 60k times faster than python and we can't even show the truth?
@ekbphd3200
@ekbphd3200 2 ай бұрын
@@talhatahir4931 Yeah, I think it depends on the benchmark task that is used. As a linguist, I'm interested in processing strings.
@NoX-512
@NoX-512 4 күн бұрын
@@talhatahir4931 The 68K claim was using Mojo’s SIMD types in a Mandelbrot function.
Typed dictionaries in Julia are faster
7:34
EKB PhD
Рет қаралды 219
Как бесплатно замутить iphone 15 pro max
00:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 6 МЛН
ПРОВЕРИЛ АРБУЗЫ #shorts
00:34
Паша Осадчий
Рет қаралды 6 МЛН
- А что в креме? - Это кАкАооо! #КондитерДети
00:24
Телеканал ПЯТНИЦА
Рет қаралды 7 МЛН
Mojo Is FASTER Than Rust
19:22
ThePrimeTime
Рет қаралды 113 М.
Mojo Community Meeting #3
1:00:06
Modular
Рет қаралды 2,4 М.
Exception vs Errors | Chris Lattner and Lex Fridman
8:02
Lex Clips
Рет қаралды 9 М.
How much faster has Mojo's dictionary gotten?
7:40
EKB PhD
Рет қаралды 2,3 М.
[UPDATE] Mojo Is Faster Than Rust - Mojo Explains More
52:09
ThePrimeTime
Рет қаралды 251 М.
Python Hash Sets Explained & Demonstrated - Computerphile
18:39
Computerphile
Рет қаралды 112 М.
Mojo🔥: a deep dive on ownership with Chris Lattner
48:50
V language - First Impression [Programming Languages Episode 2]
1:00:11
Why C is so Influential - Computerphile
10:50
Computerphile
Рет қаралды 1,9 МЛН
Mojo - the BLAZINGLY FAST new AI Language? | Prime Reacts
25:18
ThePrimeTime
Рет қаралды 171 М.
Как бесплатно замутить iphone 15 pro max
00:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 6 МЛН