objeck / objeck-lang

Objeck is a modern object-oriented programming language with functional features tailored for machine learning. It emphasizes expression, simplicity, portability, and scalability. The programming environment consists of a compiler, virtual machine, REPL shell, and command line debugger with IDE plugins.
https://objeck.org
Other
154 stars 11 forks source link

Objeck's `Hash` vs Java's `HashMap` vs C#'s `Dictionary` #463

Closed ghost closed 7 months ago

ghost commented 7 months ago

...with 1000000 elements. There is also code to iterate over and print the elements.

Memory consumption made me surprised.

.NET 8.0.1: started at 60MB and increased only to 3MB. JVM 21: started at 140MB and stopped at 200MB. Objeck 2023.9.1: started at 644MB and slowly increased to 814MB, this version is before all of the --GC_THRESHOLD optimizations. Objeck latest: started at 644MB and slowly increased to more than 1G, the memory allocation is more stable and grows faster than 2023.9.1.

Why does Objeck need too much memory?

ghost commented 7 months ago

The execution speed also surprised me. The .NET program is the fastest. The second is the Java program. The Objeck program is the slowest. There is almost no difference between the two Objeck versions. The difference between the execution speed of the Objeck program and the rest is significant. I have no idea why the Objeck program is that slow.

After the memory consumption reached 644 MB (the initialization of the Hash was done), it started to print to the console. After that is the slowest part. I guess part of it could be because the printing to the console is slow. The rest of it could be because iterating over the elements is slow. I don't know!

objeck commented 7 months ago

Thanks, I have never tried to insert 1 million items into a Hash. It should be very slow as the data structure is optimized to handle < 8k of items.

ghost commented 7 months ago

Thanks, I have never tried to insert 1 million items into a Hash. It should be very slow as the data structure is optimized to handle < 8k of items.

I don't think it's very slow to initialize the Hash. Yes, it's slower than .NET and Java. But I don't consider it to be very slow.

As I said:

After the memory consumption reached 644 MB (the initialization of the Hash was done), it started to print to the console. After that is the slowest part. I guess part of it could be because the printing to the console is slow. The rest of it could be because iterating over the elements is slow. I don't know!

I'm more concern about the memory consumption, though.

objeck commented 7 months ago

Thanks, I have never tried to insert 1 million items into a Hash. It should be very slow as the data structure is optimized to handle < 8k of items.

I don't think it's very slow to initialize the Hash. Yes, it's slower than .NET and Java. But I don't consider it to be very slow.

As I said:

After the memory consumption reached 644 MB (the initialization of the Hash was done), it started to print to the console. After that is the slowest part. I guess part of it could be because the printing to the console is slow. The rest of it could be because iterating over the elements is slow. I don't know!

I'm more concern about the memory consumption, though.

This is a a factor of the number of elements being inserted and the resizing algorithms for Hash and Map classes. Neither was designed to store 1M+ items. Both can be optimized.

objeck commented 7 months ago

Tweaked the VM setting to accommodate better inserting 1 million elements into the Map and Hash classes.